Php trim() problem

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
Gurela
Forum Newbie
Posts: 2
Joined: Tue Aug 18, 2009 8:52 am

Php trim() problem

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Php trim() problem

Post by jackpf »

Code: Select all

$string = reset(explode('<!--more-->', $string));
Gurela
Forum Newbie
Posts: 2
Joined: Tue Aug 18, 2009 8:52 am

Re: Php trim() problem

Post by Gurela »

Thanks man. That worked like a charm.

Cheers,
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Php trim() problem

Post 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);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply