Jump to content

preg_match_all issue?


adamf

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/92103-preg_match_all-issue/
Share on other sites

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); 

Link to comment
https://forums.phpfreaks.com/topic/92103-preg_match_all-issue/#findComment-471643
Share on other sites

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/92103-preg_match_all-issue/#findComment-471667
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.