Here is what I have so far:
$query = "SELECT * FROM band ORDER BY Name ASC";
$result = mysql_query($query);
while($band = mysql_fetch_array($result)) {
echo "<p>" . "<b>" . $band['Name'] . "</b>";
echo "<br>" . $band['website'] . "</br>";
echo "<br>" . $band['Description'] . "</br>";
*** I want to make it so when displayed, it finds all instances of a link (in the Website and the Description fields (Description is a text box entry), and auto converts to a hyperlink (when entered for the website www.example.com it comes back http://www.example.com etc.)
I have found dozens of examples online but I don't know how to retype them to make it work for mine.
Many thanks!!!
PHP Mysql auto hyperlink help please
Moderator: General Moderators
-
Daniel28138
- Forum Newbie
- Posts: 4
- Joined: Wed Jan 15, 2014 11:40 pm
Re: PHP Mysql auto hyperlink help please
just try jquery and/or regular expressions..
-
Daniel28138
- Forum Newbie
- Posts: 4
- Joined: Wed Jan 15, 2014 11:40 pm
Re: PHP Mysql auto hyperlink help please
I'm afraid to admit that I'm learning as I go. I would need an example to try and use or something. The stuff I already have was from snippets I found and just kept changing the words around till it worked for me, for what I have so far.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP Mysql auto hyperlink help please
new to regular expressions
PHP Manual - Regular expression
looking for examples
Google search

PHP Manual - Regular expression
looking for examples
Google search
it will help a lot more if you can create some type of code on your own 1) it shows that you are learning, willing to learn and 2) few members here will supply you with a working example if you haven't at least tried something of your own; code what you can, then post back for helpDaniel28138 wrote:I would need an example to try and use or something.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
Daniel28138
- Forum Newbie
- Posts: 4
- Joined: Wed Jan 15, 2014 11:40 pm
Re: PHP Mysql auto hyperlink help please
This is what I got so far. I spent all night and then at wake up this morning on it. But it gives an odd "H" on the page. The database is connecting. I'm trying to get it to search the field "Description" for any text links (page or email) and make them clickable when displayed (or is it more proper to call it Echo'd?)
I apologize for my lack of understanding. I'm working hard on it but so very new. I'm getting nervous though cause I'm running out of time to get this working.
The page you can see the results at is (set up just to get something working): http://www.inthisreview.com/bandsreview/viewbands.php
CODE:
$query = "SELECT * FROM band ORDER BY Name ASC";
$result = mysql_query($query);
while($band = mysql_fetch_array($result)) {
$band = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['Description']);
$band = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$band);
$band = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $band);
echo "<p>" . "<b>" . $band['Name'] . "</b>";
echo "<br>" . $band['website'] . "</br>";
echo "<br>" . $band['Description'] . "</br>";
echo "<a href=\"modifybands.php?id=" . $band['id'] . "\"> Modify Review</a>";
echo "<span> </span>";
echo "<a href=\"deletebands.php?id=" . $band['id'] . "\"> Delete Review</a>";
echo "<a href=\"modifybands.php?id=" . $band['id'] . "\"> Modify Review</a>";
echo "<span> </span>";
echo "<a href=\"deletebands.php?id=" . $band['id'] . "\"> Delete Review</a>";
}
?>
I apologize for my lack of understanding. I'm working hard on it but so very new. I'm getting nervous though cause I'm running out of time to get this working.
The page you can see the results at is (set up just to get something working): http://www.inthisreview.com/bandsreview/viewbands.php
CODE:
$query = "SELECT * FROM band ORDER BY Name ASC";
$result = mysql_query($query);
while($band = mysql_fetch_array($result)) {
$band = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['Description']);
$band = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$band);
$band = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $band);
echo "<p>" . "<b>" . $band['Name'] . "</b>";
echo "<br>" . $band['website'] . "</br>";
echo "<br>" . $band['Description'] . "</br>";
echo "<a href=\"modifybands.php?id=" . $band['id'] . "\"> Modify Review</a>";
echo "<span> </span>";
echo "<a href=\"deletebands.php?id=" . $band['id'] . "\"> Delete Review</a>";
echo "<a href=\"modifybands.php?id=" . $band['id'] . "\"> Modify Review</a>";
echo "<span> </span>";
echo "<a href=\"deletebands.php?id=" . $band['id'] . "\"> Delete Review</a>";
}
?>
-
Daniel28138
- Forum Newbie
- Posts: 4
- Joined: Wed Jan 15, 2014 11:40 pm
Re: PHP Mysql auto hyperlink help please
UPDATE....
Okay, I got it KINDA working. BUT... it's adding the original website before the link. How can I get it to not do that? I don't think it's auto adding the http first?
<?php
//connection to database
}
echo 'Connected successfully';
mysql_select_db(bands);
$query = "SELECT * FROM band ORDER BY Name ASC";
$res = mysql_query($query);
while ($band = mysql_fetch_assoc($res))
{
$news = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['Description']);
$news = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$news);
$news = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $news);
$addy = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['website']);
$addy = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$addy);
$addy = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $addy);
Okay, I got it KINDA working. BUT... it's adding the original website before the link. How can I get it to not do that? I don't think it's auto adding the http first?
<?php
//connection to database
}
echo 'Connected successfully';
mysql_select_db(bands);
$query = "SELECT * FROM band ORDER BY Name ASC";
$res = mysql_query($query);
while ($band = mysql_fetch_assoc($res))
{
$news = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['Description']);
$news = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$news);
$news = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $news);
$addy = preg_replace("/(?<!http:\/\/)(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is","<a href=http:\/\$1 target=\"_blank\">$1</a>", $band['website']);
$addy = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\" target=\"_blank\">\\0</a>",$addy);
$addy = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $addy);