One of the fields in our PHP page is a description - occasionally there are website links included. However, when pulling this data from the database table the links remain non-clickable. How can I parse text from database table as HTML in final rendered P开发者_开发技巧HP page? Thanks!
Do you mean something like this?
<?php
echo "<a href='$linkLocation'>$linkName</a>";
?>
[Edit]
Server-side you could transform the orginal text ($det[9]) like this (based on this SO question):
<div id="text"><?php
echo preg_replace_callback(
'/http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)/',
create_function(
'$matches',
'return \'<a href="http://\'. $matches[1] .\'">\'. $matches[1] .\'</a>\';'
),
$det[9]
);
?></div>
[Edit: merged the original code from your comment] [Edit: fixed typo]
Are your text stored as HTML or is it just a text containing URLs?
Follow these steps
- Change the db feild to text,
- While inserting data convert the html entities and escape the quotes.
- while retrieving do the reverse process and you can retrieve data in html format this way
精彩评论