Welcome to WebmasterWorld Guest from 54.166.191.159

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)

WebmasterWorld Senior Member 5+ Year Member



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)

10+ Year Member



substr() [us2.php.net]

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

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

10+ Year Member



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

10+ Year Member



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)

WebmasterWorld Senior Member 5+ Year Member



cool, that first ones works good. thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month