I'm just wondering how I could remove everything after a certain substring in PHP
ex:
Posted On April 6th By Some Dude
I'd like to have it so that it removes all the text including, and after, the sub string "By"
Thanks
I'm just wondering how I could remove everything after a certain substring in PHP
ex:
Posted On April 6th By Some Dude
I'd like to have it so that it removes all the text including, and after, the sub string "By"
Thanks
Austin's answer works for your example case.
More generally, you would do well to look into the regular expression functions when the substring you're splitting on may differ between strings:
How about using
explode
:Advantages:
$result[1]
would returnSome Dude
in this example)preg_replace
offers one way:By using regular expression:
$string = preg_replace('/\s+By.*$/', '', $string)
You can use
list
andexplode
functions:Use the strstr function.
The third parameter
true
tells the function to return everything before first occurrence of the second parameter.