Jump to content

Recommended Posts

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 -

Link to comment
https://forums.phpfreaks.com/topic/97886-include-php-inside-echo/
Share on other sites

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 -

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;

?>

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.