chaking Posted March 25, 2008 Share Posted March 25, 2008 I'm using tinymce text editor to populate a mysql database and then calling the content in a new page with an echo statement. The problem I'm running into is trying to store php code in mysql and have it execute after it's called within an echo statement like so... $content = "<p>Hello<?php echo "John" ?></p>"; <?php echo "$content" ?> Currently this only prints out "Hello" - Any ideas on how to proceed? Thanks for your time - Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/ Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 $content = '<p>Hello<?php echo "John" ?></p>'; echo "$content"; or $content = mysql_escape_string('<p>Hello<?php echo "John" ?></p>');// to safely store in your db echo "$content"; Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500833 Share on other sites More sharing options...
ohdang888 Posted March 26, 2008 Share Posted March 26, 2008 look... You have 4 " double quotes.... you can't do that... Your quote in the middle of the statement must be different that the ones that are defining the "borders" of the statement. $content = "<p>Hello<?php echo "John" ?></p>"; Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500834 Share on other sites More sharing options...
brevig Posted March 26, 2008 Share Posted March 26, 2008 Read this: http://us.php.net/manual/en/function.serialize.php if you want paid help, phpsupportnow.php Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500836 Share on other sites More sharing options...
chaking Posted March 26, 2008 Author Share Posted March 26, 2008 Yeah ok - I wrote it bad in the example, but that's not the problem. I was just trying to show the logic being used not the actual code. Let me write it again: On the page 1.php: <html> <head>...</head> <body> <h1><?php echo $title ?></h1> <?php echo $content ?> <p>Created On: <?php echo "$date" ?></p> </body> </html> In the dB $content is equal to this: <p>Anti Passback Violations occur when an individual is not following standard badging procedures for certain sensitive areas.</p><p><?php echo "How are you today?" ?></p> Above is exactly what is stored in the dB... Do you know how I could call it and still parse the php properly? thanks - Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500839 Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 what do you mean by parse? Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500843 Share on other sites More sharing options...
Northern Flame Posted March 26, 2008 Share Posted March 26, 2008 I'm using tinymce text editor to populate a mysql database and then calling the content in a new page with an echo statement. The problem I'm running into is trying to store php code in mysql and have it execute after it's called within an echo statement like so... $content = "<p>Hello<?php echo "John" ?></p>"; <?php echo "$content" ?> Currently this only prints out "Hello" - Any ideas on how to proceed? Thanks for your time - why not just do this: <?php $content = "Hello John"; echo $content; ?> or if the name will be stored in a variable <?php $name = "John"; $content = "Hello $name"; echo $content; ?> Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500866 Share on other sites More sharing options...
MadTechie Posted March 26, 2008 Share Posted March 26, 2008 Why you want to do it seam weird but this is how, (i assume you was going to use more than just echo thos is not tested but should work) <?php $DBData = '<p>Anti Passback Violations occur when an individual is not following standard badging procedures for certain sensitive areas.</p><p><?php echo "How are you today?"; ?></p>'; preg_match_all('/<\?(?:php)?(.*)?\?>/m', $DBData, $result, PREG_PATTERN_ORDER); foreach($result[1] as $K => $cmd) { ob_start(); eval($cmd); $str = ob_get_contents(); ob_end_clean(); $cmd = preg_quote($result[0][$K]); $DBData = preg_replace("/$cmd/m", $str, $DBData); } echo $DBData; ?> EDIT: I should really say that a ton of things can go wrong and this code is totally insecure and i wouldn't use it on my own system unless i really really really really had to.. even then i would clean it up and add some security around it, and if you do use this its exploited don't say you want warned! Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500877 Share on other sites More sharing options...
TRI0N Posted March 26, 2008 Share Posted March 26, 2008 Well fist of all from the start your php codes are missing ; at the end of each statement. example: <?php echo "John" ; ?> Before you look at anything else correct those. Second variables don't need to be in quotes: <php echo $content ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/#findComment-500988 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.