Skip to content

All topics  /  PHP

PHP String Replace Only Numbers with Space Example

PHP ·

Hi Dev,

In this tutorial, I will show you php string replace only numbers with space example. I explained simply step by step replace numbers with space in php - string. you will learn php replace numbers with space with code examples. I would like to show you php replace numbers with space.

In this example string numbers with space in PHP. in this example, we will use to preg_replace() function to Replace Numbers with Space. so Let's see following example with output.

Example : String Replace Numbers with Space


index.php

<?php    

    
    //create string
    $str = "Hello 10 developers welcome to our company's 5 year completed celebration";
    //Replace numbers with space
    $newStr = preg_replace('/[0-9]+/',' ', $str);
    echo $newStr; 

    
?>

Output:

Hello developers welcome to our company's year completed celebration 

I hope it could help you...