Welcome to WebmasterWorld Guest from 54.234.244.30

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to write out a string -- minus a few characters

i've been racking my brains

     
8:00 pm on Apr 11, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 12, 2006
posts:2493
votes: 22


hello.
i have a seemingly simple problem, but i can't for the life of me figure out how to do it.

i have a whole series of strings which include various bits of HTML, for example

$string = '<p>Blah blah blah blah blah blah';

sometimes i need to write out the entire thing, but sometimes i don't need to include the HTML tag, so i was hoping there was a way of shortening the string by 3 characters before printing it out.
i know how to do it if the 3 characters are at the end of the string... but how do you do it if the characters you don't want are at the start? (bearing in mind that all of the strings are of different lengths)

8:14 pm on Apr 11, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 19, 2004
posts:505
votes: 0


substr() [us2.php.net]

echo substr('<p>blah blah blah blah', 3);

8:20 pm on Apr 11, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 23, 2003
posts:76
votes: 0


or str_replace too.
8:25 pm on Apr 11, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 19, 2004
posts:505
votes: 0


Sure, I suppose you could do the same thing with str_replace but that would require the parsing of the entire string in order to replace the first three characters.

In this instance the occurence of the string being replace is already know making substr more efficient.

8:46 pm on Apr 11, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 12, 2006
posts:2493
votes: 22


cool, that first ones works good. thanks!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members