Remove contents after a certain string of characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Remove contents after a certain string of characters

Post 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?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Remove contents after a certain string of characters

Post 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.
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Re: Remove contents after a certain string of characters

Post by fluidbyte »

Worked like a charm, thanks so much.
Post Reply