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

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.