PHP Remove First Word from String Example
Sep 26, 2022
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...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example