Belgin Fish Belgin Fish - 2 months ago 6
PHP Question

Remove portion of a string after a certain character

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

Answer
$variable = substr($variable, 0, strpos($variable, "By"));

In plain english: Give me the part of the string starting at the beginning and ending at the position where you first encounter the deliminator.