homepage Welcome to WebmasterWorld Guest from 54.167.10.244
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

    
A difficult string to trim!
... For me anyway!
lZakl




msg:1305506
 5:15 pm on Nov 11, 2005 (gmt 0)

I have a simple problem that will be answered very quickly I am sure. I just haven't ever had the need to trim a string like this until now. This string would look like this:

$variable = "<a href=\"www.example.com/test.php?var=whatever\">link text</a>";

Now the part that I need to trim out of the string is:

href=\"www.example.com/test.php?var=whatever\">";

Now the content of var= will change in legnth, so I can't do a simple right trim and left trim. I mean since the first part of the website up to var= is a constant, I could cut all that off I suppose, but what about getting rid of the back side? The ">link text</a> .. Which is also variable in legnth? I am thinking too hard on it I think.

Any thoughts/suggestions appreciated!

-- Zak

 

Anyango




msg:1305507
 5:31 pm on Nov 11, 2005 (gmt 0)

Simple!

1) Take string poision of starting segment in the main string. = x

2) Take string position of ending segment in the main string. =y

3) remove everything between x and y

string="<a href=\"www.example.com/test.php?var=whatever\">link text</a>";

x= position of [var=]
y= position of [\">]

take left part of the string from 0 to x position
take right part of string from y to last position

concatinate them

and it's done
;)

lZakl




msg:1305508
 9:50 pm on Nov 11, 2005 (gmt 0)

That IS simple .. THANKS! My logic was obviously lost, never to return!

-- Zak

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