PHP extracting text from between two seperate points

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

PHP extracting text from between two seperate points

Postby Diagmato » Tue Dec 05, 2006 10:32 pm

Im trying to write code which:

-finds the first occurance of ... ("..." is a sentance).
-Somehow takes the sentance from between the bbcode, and stores it in another variable

I was initially thinking of explode(), however the start and ending 'tokens' are different.

Any ideas?
My Blog

Micro$oft gives you Windows, Linux gives you the full house
Diagmato
LXF regular
 
Posts: 272
Joined: Sat Apr 01, 2006 9:37 pm
Location: Cardiff

RE: PHP extracting text from between two seperate points

Postby nelz » Tue Dec 05, 2006 11:41 pm

It sounds like a job for a regular expression.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8493
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: PHP extracting text from between two seperate points

Postby TonyLB » Wed Dec 13, 2006 10:59 pm

If you can identify the end point as well, then use substr(string, start, length)
Find the start position s, the end position e
newString = substr(oldString, s+1, e-s)

Tony
In the beginning was nothing, which exploded! (Lords and Ladies, Terry Pratchett)
TonyLB
LXF regular
 
Posts: 112
Joined: Tue Apr 12, 2005 7:08 pm
Location: Wirral, UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest