homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
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
londrum




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

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)

 

justgowithit




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

substr() [us2.php.net]

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

dramstore




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

or str_replace too.

justgowithit




msg:3308752
 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.

londrum




msg:3308761
 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