vexious Posted December 2, 2007 Share Posted December 2, 2007 For some reason, whenever i have FBML enabled it puts a _ (underscore) after all URLS except the last URL in file.txt The code below is supposed to randomly pick 5 URLS links out of file.txt and display them. It does everything find but the link itself has the underscore at the end.. Any see anything wrong with my code? Any suggestions? Trim? <?php $chars = ""; $chars = file('file.txt'); function random_subarray($ary, $len, $valq) { srand($valq); shuffle($ary); return array_slice($ary, 0, $len); } # example srand((double)microtime()*1000000); $code = rand(0,100); $fred = random_subarray($chars, 5, $code); foreach ( $fred as $valq) { $fbml .= ' <div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$valq.'" style="font-weight: bold;">'.$valq.'</a></td><td valign="top" width="80%"></td></tr></table></div>'; $fbml .= '</div>'; } $fbml .= '</div>'; echo $fbml; ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 2, 2007 Share Posted December 2, 2007 The extra character is probably the newline at the end of each line from the file. The last line in the file probably does not have a newline after it. You can add the FILE_IGNORE_NEW_LINES flag as the second parameter in the file() function call to have the newline characters stripped off - $chars = file('file.txt',FILE_IGNORE_NEW_LINES); Quote Link to comment Share on other sites More sharing options...
vexious Posted December 2, 2007 Author Share Posted December 2, 2007 Wow, thanks a lot mate! I never thought of that, as there are no spaces the end of each line... Worked like a charm.. Whats weird is when i turned on FBML it added it, without it it worked fine.. Either way, THANKS! Quote Link to comment 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.