468,738 Members | 1,786 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

Please help! Stuck in miserable puddle of preg_split.

Hey... new here. Could really use some help with a preg_split i'm trying to run.

Basically, I have a string. In it is the tag: '[$' followed by some custom code, and then closed with '$]'.

Its a sort of bbcode feature I'm adding to a forum. There's one line of code that is key to the operation of the whole thing. It'll be within the [$ and $] tags, and should look like:

run (anystring.app)

I want to separate the string right after this line of code. So if the string was:

$var = "[$ phili went to the moon with gavin. run (anystring.app) $] And euan watched them go.";

It would separate into:

$var[0] = "[$phili went to the moon with gavin. run(anystring.app)";
$var[1] = " $] And euan watched them go.";

I've tried using the lookaround regex, but php 5 seems to require the expression to be a fixed length. So (?<=\[\$.*?run\s{0,1}\(\w+?\.app\)) doesn't work because of the .*?, {0,1} and +?.

Really appreciate any help on this. Maybe i've got it all backward and there's a better way of doing this. But at the end of the day I need to separate out the string just after the line "run (astring.app)" and return the array, and the line run(astring.app) needs to be within [$ and $] tags.

Tricky... but if it wasn't.. i wouldn't be here asking the community.

Feel free to burn me if i've forgotten to supply any critical info... think i've got it all though.

Jun 16 '07 #1
1 2131
5,821 Expert 4TB
I would probably just preg_split by '\[\$'. Then you can parse for 'run\((\w+)\.app\)' on each odd element of the resulting array (evens will be outside '[$ ... $]').
Jun 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Alan Bashy | last post: by
7 posts views Thread by tyler_durden | last post: by
23 posts views Thread by Jason | last post: by
5 posts views Thread by tabani | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.