This is the HTML/PHP before being stored in the database:<li><a href="<?= dots('duo/'); ?>"><?= $item->item['Manufacturer']; ?></a> <span class="divider">|</span></li>
This is the HTML/PHP after being stored in the database:
<li><a href="&lt;?= dots('duo/'); ?&gt;">&lt;?= $item-&gt;item['Manufacturer']; ?&gt;</a> <span class="divider">|</span></li>
I assign this result to a variable:
$crumbles = $details['Crumbs'];
I echo the result like so:
<?php echo html_entity_decode($crumbles); ?>
But it returns this when I view source. It’s not evaluating any of the PHP in the string.
<li><a href="<?= dots('duo/'); ?>"><?= $item->item['Manufacturer']; ?></a> <span class="divider">|</span></li>
It shows in the browser as <?= $item->item['Manufacturer']; ?> |
How can I get it to evaluate the PHP as well as display the html correctly?
EDIT: Here is the code that handles the input into the DB. It serializes the form data (url, crumbs, meta info, etc) and adds it to an ajax queue.
$("form#seo_add").submit(function(e) {
console.log(this);
var data = $(this).serializeArray(),
$commitBtn = $(this).find("button"),
form_incomplete = false,
queueData = ['seo_add', data];
When fired, the queue controller runs $this->seo->add($seo_add, $user);
Which is modeled like this:
function add($data = null, $username = null) {
if (!is_array($data) || is_null($username)) die("Expecting new pageinfo");
//if a single item is being inserted, add it to a parent array so iteration works
if (!is_array($data[0]))
{
$data = array($data);
}
foreach ($data as $key => $page)
{
if (isset($page['section'])) unset($page['section']);
if (isset($page['action'])) unset($page['action']);
$add = $this->db->insert('pageinfo', $page);
$page = array_merge(array('id'=>$this->db->insert_id()), $page);
$last_queries[$key]['type'] = 'seo_add';
$last_queries[$key]['html'] = "New page: <b>" . $page['page'] . "</b>";
$last_queries[$key]['data'] = $page;
}
if ($this->db->_error_message())
$this->db_error('Unable to insert page');
return log_changes($last_queries, $username, $this->site);
}
2
Answers
I suggest using placeholders.
I suggest not saving the html encoded. This would do the trick for you I guess:
Probably you’ve to encode the $crumbles or dots(‘duo/’) if that is user input.
Your PHP tags are being double encoded at your PHP tags
&lt;
so you can runhtml_entity_decode
over it twice.Even if your php tags were decoded they would never be interpreted by PHP since you’re echoing them out straight away, the way around this is to run what your database returns through
eval
like so: