doofy Posted November 23, 2011 Share Posted November 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/ Share on other sites More sharing options...
QuickOldCar Posted November 23, 2011 Share Posted November 23, 2011 I think this should work echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".hyperlink($row['ArticleDescription'])."</td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290667 Share on other sites More sharing options...
doofy Posted November 23, 2011 Author Share Posted November 23, 2011 That seemed to produce the exact same error. It's not happy with what I did at all. Thanks for the reply though, I appreciate the effort. Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290670 Share on other sites More sharing options...
teynon Posted November 23, 2011 Share Posted November 23, 2011 Whats line 146 Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290672 Share on other sites More sharing options...
doofy Posted November 23, 2011 Author Share Posted November 23, 2011 Line 146 is what I put in bold. When I remove the semi colon, I get no error, but it doesn't function either. Weird!!! Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290673 Share on other sites More sharing options...
MasterACE14 Posted November 23, 2011 Share Posted November 23, 2011 What QuickOldCar posted should of fixed it. Post your latest code. Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290674 Share on other sites More sharing options...
teynon Posted November 23, 2011 Share Posted November 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290675 Share on other sites More sharing options...
doofy Posted November 23, 2011 Author Share Posted November 23, 2011 I've copied and pasted it now. It's producing no errors but the function doesn't seem to be applying. Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290677 Share on other sites More sharing options...
doofy Posted November 23, 2011 Author Share Posted November 23, 2011 <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290678 Share on other sites More sharing options...
Spring Posted November 23, 2011 Share Posted November 23, 2011 Where's your mysql connection? Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290684 Share on other sites More sharing options...
doofy Posted November 23, 2011 Author Share Posted November 23, 2011 damn the code provided did work, it wasn't producing errors because there wasn't a valid http as it was in brackets. Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/251664-function-in-a-mysql-array-doh/#findComment-1290685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.