Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

only grab numbers from string php code example

Example 1: php keep only numbers in string

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

Example 2: 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 \n"); 
?>

Tags:

Php Example

Related

font color html 4 code example react printing serize of data code example mysqli join query in php code example append string to div javascript code example laravel les session code example Example of java classes Polynomial regression code example php continue on error code example editing path linux code example count inversions o(n) code example new group tabs in chrome code example c+ convert int to hex code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy