How to Find Number from String in PHP?

By Hardik Savani November 5, 2023 Category : PHP

Hi,

Hello all! In this article, we will talk about how to find number from string in php. we will help you to give example of php get number from string. This article goes in detailed on php extract number from string. This article goes in detailed on php read number from string. So, let's follow few step to create example of php take number from string.

Here, i will give you simple example how to get number value from string content in php. so let's see both code and output as bellow:

Example:

index.php

<?php

$string = 'You have 500 Dollar and 13 Rupees';

preg_match_all('!\d+!', $string, $matches);

print_r($matches['0']);

Output:

Array

(

[0] => 500

[1] => 13

)

i hope it can help you...

Tags :
Shares