Jump to content

[SOLVED] Underscore after array on URLS?


vexious

Recommended Posts

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;

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/79797-solved-underscore-after-array-on-urls/
Share on other sites

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.