• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick PHP Question

l6873

Senior member
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...
 
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. 😀

 
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. 😀



No, there might be some other text before START and after 'END'.
 
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. 😀



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.
 
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. 😀



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?
 
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.
 
Back
Top