How to Remove Numbers from String in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hello Guys,

Now, let's see an example of how to remove numbers from string php. if you want to see an example of php remove all numbers from string then you are in the right place. you will learn php remove numbers from string. you can understand a concept of remove numbers from string php. you will do the following things for remove all numbers from string php.

There are several ways to remove numbers from string value in php. i will give you simple two examples using preg_replace() function. so, let's see the below example.

Example 1: index.php

<?php

$string = "This is a Cars24 Goo23332gle.".

$newString = preg_replace('/[0-9]+/', '', $string);

print($newStrin);

?>

Output:

This is a Cars Google.

Example 2: index.php

<?php

$string = "This is a Cars24 Goo23332gle.".

$newString = preg_replace('/\d/', '', $string);

print($newStrin);

?>

Output:

This is a Cars Google.

I hope it can help you...

Tags :
Shares