ItSolutionStuff.com

How to Remove Numbers from String in PHP?

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

PHP nl2br() Function Example Tutorial

Read Now →

PHP Google Recaptcha V2 Example Tutorial

Read Now →

How to Add Watermark in Image using PHP?

Read Now →

How to Convert String into Array in PHP?

Read Now →

How to Subtract Minutes from DateTime in PHP?

Read Now →

PHP Add Minutes to Time Example

Read Now →

How to Add Days to Date in PHP?

Read Now →

How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?

Read Now →

How to Connect SSH using PHP?

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

How to Convert Object into Array in PHP?

Read Now →

MySQL Query to Get Current Month Data Example

Read Now →