homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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)

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)

substr() [us2.php.net]

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


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

or str_replace too.


 8:25 pm on Apr 11, 2007 (gmt 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)

cool, that first ones works good. thanks!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved