primefalcon Posted April 23, 2010 Share Posted April 23, 2010 for example say I have a variable like so <?php $variable = "a bunch of stuff that [rofl]that isn't here[/rofl]or is it?"; ?> Is there anyway to extract the rofl content to a 2nd variable like <?php $variable = "a bunch of stuff that or is it?"; $variable2 = "that isn't here"; ?> I realize it's probably a simple case of preg matching and replacing but, that's not something I am real familiar with Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 23, 2010 Share Posted April 23, 2010 <?php $variable = "a bunch of stuff that [rofl]that isn't here[/rofl]or is it?"; preg_match('%[rofl](.*?)[/rofl]%i', $variable, $out); $variable = str_replace($out[0], '', $variable); $variable2 = $out[1]; ?> Quote Link to comment Share on other sites More sharing options...
primefalcon Posted April 23, 2010 Author Share Posted April 23, 2010 Didn't quite work for me, testing that code got me a bunch stuff that [rl]that isn't here[/rl]or is it? for the first variable and the second variable was actually empty Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 23, 2010 Share Posted April 23, 2010 ah oops, total screw up on my part, it is still too early to think Try this $variable = "a bunch of stuff that [rofl]that isn't here[/rofl]or is it?"; preg_match('%\[rofl\](.*?)\[/rofl\]%i', $variable, $out); $variable = str_replace($out[0], '', $variable); $variable2 = $out[1]; echo $variable.'<br />'.$variable2; Quote Link to comment Share on other sites More sharing options...
primefalcon Posted April 23, 2010 Author Share Posted April 23, 2010 perfect thank you very much, I really need to get into preg match a little more, very powerful. I've messed with a bit of ereg and eregi but... I see what happened I do that a lot with stuff myself, forgot to escape Anyhow thanks a ton that solved my problems :-) Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 23, 2010 Share Posted April 23, 2010 eek eregi! Yeah regular expressions are great Quote Link to comment Share on other sites More sharing options...
primefalcon Posted April 23, 2010 Author Share Posted April 23, 2010 yup and what I am looking at doing looks perfect :-) <?php $variable = "a bunch of stuff that [rofl]<code>that isn't here</code>[/rofl]or is it?"; preg_match('%\[rofl\](.*?)\[/rofl\]%i', $variable, $out); $variable2 = htmlentities($out[1]); $variable = str_replace($out[0], "$variable2", $variable); echo "modified variable is: " . $variable; ?> now I am figuring if I run that second variable through geshi before I re-insert it, it should make for a nice syntax highlight. Thx again :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.