seperating words

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

nainil
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Mar 16, 2003 9:03 pm
Location: India
Contact:

seperating words

Postby nainil » Tue Mar 18, 2003 4:48 am

Hi,

I need to seperate the following from the below LINE :
1. IP Address
2. The words after &q= . ie. web hosting in mumbai
3. The Date.

Please HELP ASAP!!
P.S.Note: This below text starting from 202.63.171.3 to 4322)" is ONE SINGLE LINE CODE.


202.63.171.3 - - [14/Mar/2003:16:58:59 +0000] "GET /web-hosting-mumbai/index.php HTTP/1.1" 200 12300 "http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=web+hosting+in+mumbai" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"



I am using
<?php

$flag = "false";

if ($fp = fopen("web.log","r")) {

while (!feof($fp)) {

$line = fgets($fp,1024);

if (ereg("\$",$line)) {
$flag="false";
}
if ($flag=="true") {
$linearray = explode(" ",$line);
$ip = $linearray[0];
$date = $linearray[1];
$keywords = $linearray[2];
echo "$ip $date $keyowrds";
}
if (ereg("\^",$line)) {
$flag = "true";
}

}
} else {
echo "Could not open file";
}

?>

Hadleigh
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK
Contact:

Postby Hadleigh » Tue Mar 18, 2003 10:34 am

I haven't tested this but I hope it helps!

Code: Select all

function sep($string){

   $ip=explode("- -", $string);
   $ip=trim($ip[0]);
   
   $date=explode("]", $ip[1]);
   $date=str_replace("", "[", $date[0]);
   $date=trim($date[0]);
   
   $search_string=explode("&q=", $ip[1]);
   $search_string=explode("\"", $search_string[1]);
   $search_string=trim($search_string[0]);

   $you_have["ip"]=$ip;
   $you_have["date"]=$date;
   $you_have["search_string"]=$search_string;
   
   return $you_have;
}


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher and 2 guests