mysql - PHP PDO Querying code from database doesn't show, only in source -
i'm using pdo query data database have section raw php code doesn't show up, in source if it's trying run.
i have slashes stripped , have echoed under pre/code tags i'm wondering why won't show on page.
database
id name(varchar) code (longtext) 1 test <?php echo /'hello world/'; ?>
php file
<?php try { $db = new pdo('mysql:host=localhost;dbname=$dbname;charset=utf8', '$username', '$password'); $db->setattribute(pdo::attr_errmode, pdo::errmode_exception); $db->setattribute(pdo::attr_emulate_prepares, false); $stmt = $db->prepare('select name, codeone table_one id = :id'); $stmt->bindparam(':id', '1'); $stmt->execute(); while ($row = $stmt->fetch(pdo::fetch_assoc)) { echo $row['name'] . '<pre><code>'. stripslashes($row['codeone']) .'</code></pre>'; } } catch(pdoexception $e) { return $e->getmessage(); }; ?>
what sees
test
view source
test<pre><code><?php echo "hello";?></code></pre>
well use htmlspecialchars()
encode string, e.g.
echo htmlspecialchars('<?php echo "hello";?>');
what see:
<?php echo "hello";?>
source code:
<?php echo "hello";?>
or if want fancy use: highlight_string()
, gives nice color string:
echo highlight_string('<?php echo "hello";?>', true);
Comments
Post a Comment