Page 1 of 1

Php trim() problem

Posted: Tue Aug 18, 2009 9:07 am
by Gurela
I'm trying to trim the end of a string starting from a specific tag like in the examle listed below and I'm stuck. Any help would be greatly appreciated.

This is the what the text looks like without the trim.
Here is the sample <!--more--> I don't want this to display.

This is what I want to display
Here is the sample

so basically trim everything from <!--more--> to the end.

Re: Php trim() problem

Posted: Tue Aug 18, 2009 9:33 am
by jackpf

Code: Select all

$string = reset(explode('<!--more-->', $string));

Re: Php trim() problem

Posted: Tue Aug 18, 2009 10:06 am
by Gurela
Thanks man. That worked like a charm.

Cheers,

Re: Php trim() problem

Posted: Tue Aug 18, 2009 10:10 am
by pickle
More code, but it might be faster, and I think more obvious (which is useful if you ever revisit this code again):

Code: Select all

$string = substr($string,0,strpos('<!--more-->')-1);