What function should I use to search for a string in a paragraph and then delete everything including and after that string?
So if I had a paragraph
“Marry had a little lamb and the wolf ate them all. Then marry went to Walmart for more lambs.”
And I used a function to search “lamb” everything including lamb and stuff after it should be deleted. So the resulting text should be “Marry had a little”
For this simple task
strstr()would work; starting from PHP 5.3, if you set the last parameter to true.This returns only the part until
lamb.The alternative would be fiddling with
strposandsubstror for lazy people ,} a regex.