Link to home
Start Free TrialLog in
Avatar of PeterdeB
PeterdeBFlag for Netherlands

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

Open in new window

Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Try using '\n' instead of "<br>"
Avatar of PeterdeB

ASKER

Hi bportlock,

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],$sGoogle))  
                     {
                     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],$sGoogle))  
                         {
                         fputs($regels, $urls[$i]."\n");
                       
                         }
 
             }
  fclose($regels);
This code... What it writes to url.dat? Is the file empty?
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
Rok-Kralj,

Yes it is empty.

Dweep
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
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],$sGoogle))  
                         {
                         fputs($regels, $urls[$i]."\n");
                       
                         }
 
             }
  fclose($regels);
?>


which produces

bbb
ccc

Hi Folks,

I'm stuck on the parameter ' a' the only which allows me to write anything to that file.

Kind regards,

Dweep
bportlock,

No the data is not blank.

Kind regards,

Dweep
can you supply some of the data and the expected output?
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?
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 )
Thanks!