Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php keep only numbers in string

$str = preg_replace('/[^0-9.]+/', '', $str);
Comment

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

$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 :: remove duplicate values in array php 
Php :: importing current year in laravel blade 
Php :: Enable / Disable modules in PHP 
Php :: remove last letter php 
Php :: php uppercase each word 
Php :: php display all rows in mysql table 
Php :: laravel check auth 
Php :: base64 decode in php 
Php :: import class route laravel 
Php :: wordpress featured image as a background image 
Php :: wordpress get fiture image 
Php :: Download a file from external server using PHP - Move one project to another server 
Php :: wordpress get username 
Php :: adding css to php file 
Php :: previous url laravel 
Php :: php remove everything after character 
Php :: php ip address of visitor 
Php :: array push object php 
Php :: session_destroy not working 
Php :: php clear output 
Php :: carbon parse subday 
Php :: db symfony 
Php :: laravel check if get is empty 
Php :: rollback laravel transaction 
Php :: change laravel mix to run on different port 
Php :: php subtract mins to datetime 
Php :: get last two numbers from int php 
Php :: bcrypt laravel 
Php :: laravel validation integer 
Php :: laravel print exception message 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =