I am using mysqli queries in php script to pull data from mysql database table and display it on website.
Some of the data includes links, but they are formatted in specific format. The links are formatted as #Link Name#http://www.link.com
So first # sets the name and the second # sets the hyperlink.
I would need my php script to parse this and display as normal hyperlink on a website.
Here is the php scrip:
<?php
include('mysql_connection.php');
$c = mysqlConnect();
$locale = $_GET['locale'];
$last_news_id = $_GET['news_id'];
sendQuery ("set character_set_results='utf8'");
sendQuery ("set collation_connection='utf8_general_ci'");
if (strcmp($locale,"en") != 0)
$locale = "en";
$result = sendQuery("SELECT * FROM news WHERE id > ".$last_news_id." and locale = '" . $locale . "' ORDER BY id DESC LIMIT 10");
echo '<table width=\"100%\">';
while($row = mysqli_fetch_array($result, MYSQL_NUM))
{
echo '<tr><td width=\"100%\"><b>Date: </b>'.$row[2].'</td></tr>';
echo '<tr><td width=\"100%\">'.nl2br($row[3]).'</td></tr>';
echo '<tr><td width=\"100%\"><hr style="height: 2px; border: none; background: #515151;"></td></tr>';
}
echo '</table>';
mysqliClose($c);
?>
EDIT: I added the line and it sort of helped with one issue:
echo '<tr><td width=\"100%\">'.preg_replace('/#([^#]*)#.*/', '<a href="$2" target="_blank">$1</a>', $row[3]).'</td></tr>';
It still opens the existing page and not the hyperlink. I guess the $2 should be the hyperlink, the value that goes after second #. However, I’m not totally sure how to code this into php.
I assume $row[3] is the data includes links, by using regular expression,