PHP How to Remove Numbers From String Tutorial

Reading Time: 2 minutes
981 Views

Inside this article we will see the concept i.e PHP How to Remove Numbers From String Tutorial. Article contains the classified information about how to remove numbers from string php.

If you are looking for a solution i.e php remove all numbers from string then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

“Numbers” String Examples

OnlineWeb1001Tutor, 1001WebTutor, LearnCodeIgniter100

Read More: Laravel 9 How To Get All Application Routes Tutorial

Let’s get started.

Application Programming

Create a folder say remove-numbers in your localhost directory. Create a file index.php into it.

Method #1

Open index.php file and write this code into it.

<?php

$string = "This is a text OnlineWeb1001Tutor.";

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

echo $newString;

When you execute above program, you will get the output without any numbers.

This is a text OnlineWebTutor.

Read More: Laravel 9 Redirection with Form Inputs Example Tutorial

Method #2

Open index.php file and write this code into it.

<?php

$string = "This is a text OnlineWeb1001Tutor.";

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

echo $newString;

When you execute above program, you will get the output without any numbers.

This is a text OnlineWebTutor.

We hope this article helped you to learn PHP How to Remove Numbers From String Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.