PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
rxsid
Forum Commoner
Posts: 82 Joined: Thu Aug 29, 2002 12:04 am
Post
by rxsid » Tue Nov 12, 2002 12:14 pm
Hi all,
I can get the url no prob, but I'm having trouble extracting what i would like:
Code: Select all
$url = "http://somesite.com";
$firstArray = array ("apple", "banana", "new pears", "spicy something");
$secondArray = array ("blue", "green", "bright yellow", "another color with spaces");
$fp = fopen("$url", "r");
$contents = fread($fp, 100000);
fclose($fp);
$line = explode("\n", $contents );
$linecnt = count($line);
for ($cnt=0; $cnt < $linecnt;$cnt++) {
if (eregi(array($firstArray,$lineї$cnt]))) { //NOT SURE HERE?
$finalArray1ї] = $lineї$cnt];
}
if (eregi(array($secondArray,$lineї$cnt]))) {
$finalArray2ї] = $lineї$cnt];
}
}
this isn't working, but not sure how to accomplish loading the 2 different arrays with the content wanted in $firstArray & $secondArray, (& yes, I need to have some items in those arrays contain a space)?
thanks...
rxsid
Forum Commoner
Posts: 82 Joined: Thu Aug 29, 2002 12:04 am
Post
by rxsid » Tue Nov 12, 2002 1:12 pm
some further clarification:
Code: Select all
$url = "http://somesite.com";
$fp = fopen($url, "r");
$contents = fread($fp, 150000);
fclose($fp);
$siteInfo = explode("\n",$contents);
$linecnt = count($siteInfo);
for ($cnt=0; $cnt < $linecnt;$cnt++) {
if (eregi("string1",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("string2",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("string3",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("string4",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("string5",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("stringA",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("stringB",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("stringC",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("stringD",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
if (eregi("stringE",$siteInfoї$cnt])) {
echo $siteInfoї$cnt];
}
}
the above works great.
i would just like to clean to code up, perhaps with a function, or loading arrays with my search strings.
thanks...