adamf Posted February 20, 2008 Share Posted February 20, 2008 Hi, I am writing a bit of code so that I can place php inside a content management system that I have developed by using tags like: [code=php:0]echo 'red'; [/code] The code above works but if I enter the code as seen below then it prints what you see on the page and doesn't treat it as php code...i'm very confused?!: [code=php:0] echo 'red'; [/code] This is the code that I am using... preg_match_all('/\[code=php:0](.*?)\[\/php]/', $content, $data, PREG_SET_ORDER); $find[] = ""; $replace[] = ""; foreach ($data as $info) { $main = $info[1]; ob_start(); eval("$main"); $f = ob_get_contents(); ob_end_clean(); $find[] = $info[0]; $replace[] = $f; } $content = str_replace($find, $replace, $content); return $content; If you could point out what the issue is I would be very greatful Regards, Adam Quote Link to comment Share on other sites More sharing options...
Dragen Posted February 20, 2008 Share Posted February 20, 2008 I've got a similar problem with a bbcode system I'm making. It's something to do with the newline character. I haven't fixed it yet, but it was quite late last night I was working on it. I tried converting newlines to <br /> in hopes that it would work, but didn't seem to: preg_match_all('\[code=php:0](.*?)\[\/php]', $content, nl2br($data), PREG_SET_ORDER); Quote Link to comment Share on other sites More sharing options...
adamf Posted February 20, 2008 Author Share Posted February 20, 2008 If I have: [code=php:0] echo 'Display this text'; echo 'And this text'; [/code] Can anything other than preg_match_all() be used to return the code below as lets say $value ? echo 'Display this text'; echo 'And this text'; I can then run $value through eval() to have it display as I need... I just don't understand how if everything is on one line it works but as soon as a break is made it doesn't? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 20, 2008 Share Posted February 20, 2008 Use the /s modifier to make . match new lines. Quote Link to comment Share on other sites More sharing options...
adamf Posted February 20, 2008 Author Share Posted February 20, 2008 Thank you for the advice but i'm not quite sure what you mean? If I have: preg_match_all('/\[code=php:0](.*?)\[\/php]/', $content, $data, PREG_SET_ORDER); How would I use the /s modifier to make . match new lines? Thank you for your patience Quote Link to comment Share on other sites More sharing options...
effigy Posted February 20, 2008 Share Posted February 20, 2008 The format for a regular expression is delimiter pattern delimiter modifiers. /\ (.*?)\[\/php]/s Quote Link to comment Share on other sites More sharing options...
Dragen Posted February 20, 2008 Share Posted February 20, 2008 ah, that worked for me! I can never remember what all of the delimiter modifiers mean.. I hope it worked for adam too! Quote Link to comment Share on other sites More sharing options...
adamf Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks...it works just fine but I have a problem now with the WYSIWYG editor that i'm using! Great advise though...thanks alot Regards, Adam 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.