ItSolutionStuff.com

How to Find Number from String in PHP?

By Hardik Savani • May 14, 2024
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: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to get HTML Tag Attribute Value in PHP?

Read Now →

How to Get HTML Tag Value in PHP?

Read Now →

PHP Calculate Time Difference Between Two Dates in Hours Example

Read Now →

PHP Generate QR Code using Google Chart API Example

Read Now →

PHP Array Get Previous Element from Current Key

Read Now →

PHP Explode Every Character into Array Example

Read Now →

PHP Remove Element from Array by Value Example

Read Now →

PHP Curl Request with Username and Password Example

Read Now →

PHP Check Word Exist in String or Not Example

Read Now →

How to Convert Array Values to Lowercase in PHP?

Read Now →