Link to home
Create AccountLog in
Avatar of HiTechFail
HiTechFailFlag for United States of America

asked on

Using implode/explode with strings

My current script below keeps adding a little space after every URL when it fopens it except the last one in the text file..I'm guessing this is \n..I want to make it trim that so it's fopen'ing a url with no spaces or anything.

Such as (only example):

It's doing this:
fopen("http://google.com ");

I want it to open:
fopen("http://google.com");
<?php
$loadit = file('websites.txt'); //loads a website list file with about 10 websites in it
$sites = trim($loadit); //This is what's giving an error (Notice: Array to string conversion in test.php)
 
foreach ($sites as $res)
{
echo $res;
$fp=fopen($res,'r');
if (!$fp) die('cant fopen '.$res);
$read = '';
while (!feof($fp))
{
$read.=fread($fp,1000000);
}
fclose($fp);
 
$save = $read;
$findme   = 'Powered by Google';
$searchit = strstr($save, $findme); //Searches the websites for a phrase I set which is currently just a random phrase to use as example
 
if ($searchit === false) {
    echo "<font color=\"red\">Not Found</font><br>";
} else {
    echo "<font color=\"green\">Found</font><br>";
    $found = $res;
    $fp=fopen('foundsites.txt','w');
    if (!$fp) die('cant fopen');
    fwrite($fp,$found);
    fclose($fp);
}
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of HiTechFail

ASKER

Thank you. :D