Jump to content

Recommended Posts

 

I'm writing a script that displays the list of servers in my web monitoring system and enables or disables them at will. I will only explain what is relevant to my current problem.

My page configuration file contains lines each with url, email, size and command separated by delimeters. Example of one line is:

 

 

  http://badix/monitor.html  stinel@midlan.ke  154   /usr/local/ml-survey/log.sh "badix" "http request failed" page.log

 

 

 

I know what to do in normal case would be to open the file, read line by line, create a datastructure, explode the lines and insert the results in the data structure.

My current problem is that I am only interested in the url part of every line because I want to later parse the url and extract the server name. So my question is, how do I read only the url part of every line.???

 

Secondly, I will have an array of all the Urls in the file ( collected from each line). To obtain the server name, should I use parse_url or explode funtions???

Please help. Thank you.

 

 

/

/List for storing the parsed lines

$arParsedLines = array();

 

//read file

$nFileHandle = fopen("page.conf", "r+");

 

while (!feof($nFileHandle))

{

  //echo "--------------------------------------------------------------------<br>\n";

  $strCurrentLine = fgets ( $nFileHandle, 4096 );

 

  if (strlen($strCurrentLine) < 7)

  {

  continue;

  }//end if (strlen($strCurrentLine) < 7)

 

  //echo "strCurrentLine enthält: ->".$strCurrentLine."<-<br>\n";

 

  //echo "Datenstruktur wird angelegt: <br>\n";

  $arThisLine = array("url" => "");

 

  //echo "Datenstruktur arThisLine: <br>\n";

  //print_r($arThisLine);

 

  /

Link to comment
https://forums.phpfreaks.com/topic/71374-using-fgets-under-special-circumstances/
Share on other sites

might be a dirty way but if you explode by line and then by space then the first word of each line will be the webaddress as you wont have any spoaces in a webaddress and well if that is the case that you do then when inserting replace webaddress spaces with %20

 

 

Regards

Liam

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.