Home » Categories » PHP Tricks

Extract numbers from a string

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

 

Reference:

https://stackoverflow.com/questions/6278296/extract-numbers-from-a-string

Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Curl Image using php but empty file is created
Viewed 450 times since Fri, Dec 24, 2021