Quick PHP Question

l6873

Senior member
Sep 9, 2005
255
0
0
Let's say I have a variable like this:

$string = 'START this is some random text END';

How would I go about extracting everything between the words 'START' and 'END'? I could just look through the manual but someone probably knows...
 

Injury

Lifer
Jul 19, 2004
13,066
2
81
Maybe more specific... are you trying to just find the information between the first and last word of the variable?

Maybe we could think of a better solution if you tell us what it is for. :D

 

l6873

Senior member
Sep 9, 2005
255
0
0
Originally posted by: Injury
Maybe more specific... are you trying to just find the information between the first and last word of the variable?

Maybe we could think of a better solution if you tell us what it is for. :D



No, there might be some other text before START and after 'END'.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: l6873
Originally posted by: Injury
Maybe more specific... are you trying to just find the information between the first and last word of the variable?

Maybe we could think of a better solution if you tell us what it is for. :D



No, there might be some other text before START and after 'END'.

The two suggestions I gave you would work in that case. If you don't want to learn about regular expressions, use SPLIT. Or use strpos and substr.
 

l6873

Senior member
Sep 9, 2005
255
0
0
Originally posted by: mugs
Originally posted by: l6873
Originally posted by: Injury
Maybe more specific... are you trying to just find the information between the first and last word of the variable?

Maybe we could think of a better solution if you tell us what it is for. :D



No, there might be some other text before START and after 'END'.

The two suggestions I gave you would work in that case. If you don't want to learn about regular expressions, use SPLIT. Or use strpos and substr.


I've used regular expressions in the past. Doesn't split use regular expressions as well?
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
here's a simple way

if your string contains more than one start and end points you'll have to do a lot of legwork though.