Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Extract Numbers From a String in PHP

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
$outputString = preg_replace('/[^0-9]/', '', $string);  
echo("The extracted numbers are: $outputString 
"); 
?> 
Comment

php get only numbers from string

$str = 'In My Cart : 11 items';
$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
Comment

php get number from string

function get_numerics ($str) {
    preg_match_all('/d+/', $str, $matches);
    return $matches[0];
}

// this function will return an array of number

$str = "3 dogs were running!";
echo (get_numerics($str)[0]); 

// output 3
Comment

Extract Numbers From a String in PHP

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
$int = (int) filter_var($string, FILTER_SANITIZE_NUMBER_INT);  
echo("The extracted numbers are: $int 
"); 
?> 
Comment

Extract Numbers From a String in PHP

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
preg_match_all('!d+!', $string, $matches);
print_r($matches); 
?> 
Comment

PREVIOUS NEXT
Code Example
Php :: how to style echo in php 
Php :: $posts- links() laravel design error 
Php :: check if value is not null in db laravel 
Php :: php JSON_PRETTY_PRINT and ? 
Php :: WP_Comment_Query get total number of comments fetched 
Php :: MForm Attribute für Felder 
Php :: combine array except common ones php 
Php :: laravel faker boolean 
Php :: how create new command in laravel 
Php :: php detect mobile 
Php :: decimal to binary php 
Php :: get one column in all associative array in collection laravel 
Php :: php change an associative array into indexed array 
Php :: php parse json 
Php :: php array move first element to last 
Php :: how handle the number with k in laravel balde 
Php :: decode utf-8 php 
Php :: how change default value for enum colun in laravel 
Php :: php get random element from array 
Php :: check php version linux terminal 
Php :: add csrf token laravel 
Php :: laravel child relation order by desc 
Php :: deleteAll cakephp 2 
Php :: how to print all session variables in php 
Php :: laravel migration add column after 
Php :: php write file 
Php :: generate token in php 
Php :: delete all rows from table laravel 
Php :: laravel relationship with for single data 
Php :: php sha512 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =