Page 1 of 1

Remove contents after a certain string of characters

Posted: Tue Jul 08, 2008 1:49 pm
by fluidbyte
Say I have a variable containing a text string:

Code: Select all

$myStuff="This is my stuff and I want to remove <!--STOP--> everything after the stop comment"
Is there a way to remove everything after (and including) the STOP comment?

Re: Remove contents after a certain string of characters

Posted: Tue Jul 08, 2008 2:26 pm
by jayshields

Code: Select all

$myStuff="This is my stuff and I want to remove <!--STOP--> everything after the stop comment";
$parts = explode('<!--STOP-->', $myStuff);
$myStuff = $parts[0];
Is the first thing that comes to mind.

Re: Remove contents after a certain string of characters

Posted: Tue Jul 08, 2008 2:37 pm
by fluidbyte
Worked like a charm, thanks so much.