Jump to content

function in a mysql array. doh!


doofy

Recommended Posts

I hope I'm not being a vampire here sucking the life out of you guys, but I can't find any resources in google that explains how to properly use this function in a mysql array. All it does is add a url for any urls added in plaintext.

 

Code:

---

<?php

 

function hyperlink ($string) {

$string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string);

$string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string);

$string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string);

return $string;

}

 

// mysql connection

 

$result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC");

 

echo "<table border='0'>";

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>"hyperlink(. $row['ArticleDescription'] .);"</td></tr>";

  echo "<tr><td  class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>";

  echo "</tr>";

  echo "<td align='left' valign='top'> </td>";

}

echo "</table>";

 

mysql_close($con);

?>

---

 

Error:

"Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/doofyd5/public_html/trevor/playground/displayarticles.php on line 146"

 

(Clearly an error where I'm abusing the heck out of the bolded line. Any ideas on how to properly code this?

Link to comment
Share on other sites

doofy, if that line is line 146, then you didn't actually run QuickOldCar's code in place of that.

 

I think this should work

 

echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".hyperlink($row['ArticleDescription'])."</td></tr>";

 

 

Swap out that line with what he posted and try again.

Link to comment
Share on other sites

<?php

 

function hyperlink ($string) {

$string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string);

$string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string);

$string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string);

return $string;

}

 

//connection

 

$result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC");

 

echo "<table border='0'>";

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>";

  echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".hyperlink($row['ArticleDescription'])."</td></tr>";  echo "<tr><td  class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>";

  echo "</tr>";

  echo "<td align='left' valign='top'> </td>";

}

echo "</table>";

 

mysql_close($con);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.