spliting string by [stuff]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

spliting string by [stuff]

Post by Erfangc »

Say I have a string "hello world [stuff] //code source [/stuff] bla bla bla". How can I split this string each time the function encounters the stuff tag? So far I have tried split("[[stuff].[/stuff]]",$str) with no luck. I also tried several variations and the strtok() method.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

explode() may be more easily handled.
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

Post by Erfangc »

feyd wrote:explode() may be more easily handled.
I need to open it on a [stuff] tag and a closing [/stuff] tag but explode only takes one separator.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can call it on the resulting array elements.
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

Post by Erfangc »

feyd wrote:you can call it on the resulting array elements.
sounds like I'm gonna need a recurisve function.

EDIT: Nevermind, I think I found a non mind twisting way
Post Reply