Skip to content

How to separate integer from string in PHP?

 phpCopy<?php 
$string = 'Sarah has 4_dolls  8_dolls and 6 bunnies.';
$int = (int) filter_var($string, FILTER_SANITIZE_NUMBER_INT);  
echo("The extracted numbers are: $int \n"); 
?> 
See also  Python code snippet - How to send a command to cmd ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.