Archimedees Posted October 1, 2007 Share Posted October 1, 2007 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); / Quote Link to comment https://forums.phpfreaks.com/topic/71374-using-fgets-under-special-circumstances/ Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71374-using-fgets-under-special-circumstances/#findComment-359152 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.