PHP Remove First Word from String Example

03-Apr-2023

.

Admin

PHP Remove First Word from String Example

Hi Dev,

In this example, you will learn php remove first word from string example. you can see how to remove first word from string in php?. let’s discuss about remove first word from string in php example. you can see how to use function to remove first word from string in php? .

There are tow example to remove First word from strings in PHP. in this example, we will use to substr() and preg_replace() function to remove First word. so Let's both the following example with output.

Example 1: Remove First Word from String


index.php

<?php

$str = "Hello Nicesnippets.com";

// Remove First Word from String

$result = preg_replace("/^(\w+\s)/", "", $str);

echo $result;

?>

Output:

Nicesnippets.com

Example 2: Remove First Word from String

index.php

<?php

$str = "Hello Mywebtuts.com";

// Remove First Word from String

$result = substr(strstr($str," "), 1);

echo $result;

?>

Output:

Mywebtuts.com

I hope it could help you...

#PHP