PeterdeB
asked on
How to format this output?
Hi Folks,
Given the code below I get the file url.dat filled with urls. Now I would like to know how I can format the output so I get a list with one url per line?
Kind regards,
Dweep
Given the code below I get the file url.dat filled with urls. Now I would like to know how I can format the output so I get a list with one url per line?
Kind regards,
Dweep
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls))+1;$i++)
{
if (!stristr($urls[$i],$sGoogle))
{
fputs($regels, $urls[$i])."<br>";
}
}
fclose($regels);
Try using '\n' instead of "<br>"
ASKER
Hi bportlock,
I tried that but it doesn't change the output.
Kind regards,
Dweep
I tried that but it doesn't change the output.
Kind regards,
Dweep
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls)) +1;$i++)
{
if (!stristr($urls[$i],$sGoog le))
{
fputs($regels, $urls[$i])."<br>\r\n";
}
}
fclose($regels);
for($i=1;$i<(count($urls))
{
if (!stristr($urls[$i],$sGoog
{
fputs($regels, $urls[$i])."<br>\r\n";
}
}
fclose($regels);
"I tried that but it doesn't change the output."
I've just noticed a little typo in your code
Try this
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls)) +1;$i++)
{
if (!stristr($urls[$i],$sGoog le))
{
fputs($regels, $urls[$i]."\n");
}
}
fclose($regels);
I've just noticed a little typo in your code
Try this
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls))
{
if (!stristr($urls[$i],$sGoog
{
fputs($regels, $urls[$i]."\n");
}
}
fclose($regels);
This code... What it writes to url.dat? Is the file empty?
ASKER
Hi dr dedo and bportlock,
I'm not sure what is going on but when using your code, it doesn't write a thing. I suppose I'm overlooking something somewhere but I'm not sure what?
I just transferred the script to my server to see what it does there but likewise, the file url.dat remains empty.....hmz.....
Kind regards,
Dweep
I'm not sure what is going on but when using your code, it doesn't write a thing. I suppose I'm overlooking something somewhere but I'm not sure what?
I just transferred the script to my server to see what it does there but likewise, the file url.dat remains empty.....hmz.....
Kind regards,
Dweep
ASKER
Rok-Kralj,
Yes it is empty.
Dweep
Yes it is empty.
Dweep
ASKER
Ooops...I see something now. The only time data was written was when I used the 'a' instead of 'w' parameter.....I must have overlooked that when copying pasting my code to EE.
My apologize for that.....obviously 'a' appends text....but still no clue why 'w' doesnt write.
Dweep
My apologize for that.....obviously 'a' appends text....but still no clue why 'w' doesnt write.
Dweep
Maybe yor data is blank. Here is a "working version"
<?php
$urls = array("aaa", "bbb", "ccc");
$sGoogle = "a big string with bbb in it";
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls)) +1;$i++)
{
if (!stristr($urls[$i],$sGoog le))
{
fputs($regels, $urls[$i]."\n");
}
}
fclose($regels);
?>
which produces
bbb
ccc
<?php
$urls = array("aaa", "bbb", "ccc");
$sGoogle = "a big string with bbb in it";
$regels= fopen('url.dat', 'w');
for($i=1;$i<(count($urls))
{
if (!stristr($urls[$i],$sGoog
{
fputs($regels, $urls[$i]."\n");
}
}
fclose($regels);
?>
which produces
bbb
ccc
ASKER
Hi Folks,
I'm stuck on the parameter ' a' the only which allows me to write anything to that file.
Kind regards,
Dweep
I'm stuck on the parameter ' a' the only which allows me to write anything to that file.
Kind regards,
Dweep
ASKER
bportlock,
No the data is not blank.
Kind regards,
Dweep
No the data is not blank.
Kind regards,
Dweep
can you supply some of the data and the expected output?
ASKER
Hi bportlock,
Yes I can. The data are urls. The expected output is a list with these urls. From a huge list of urls I pick out the ones not containing the google string.
Dweep
Ps is that sufficient?
Yes I can. The data are urls. The expected output is a list with these urls. From a huge list of urls I pick out the ones not containing the google string.
Dweep
Ps is that sufficient?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just noticing (after pressing SUBMIT) you want the ones that do not contain the Google string. Change
if ( stripos( $aUrl, $sGoogle ) !== false )
to
if ( stripos( $aUrl, $sGoogle ) === false )
if ( stripos( $aUrl, $sGoogle ) !== false )
to
if ( stripos( $aUrl, $sGoogle ) === false )
ASKER
Thanks!