Reputation: 588
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 PHP page? Thanks!
Upvotes: 0
Views: 553
Reputation: 2994
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]
Upvotes: 1
Reputation: 361
Follow these steps
Upvotes: 0