Searching keywords from array
Posted on
16th Feb 2014 07:03 pm by
admin
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still learning PHP and I have been for a few months now, but every now and then I get stuck on small things. I hope to become a regular here, but I know I cannot contribute much at the moment while im still learning. Hopefully once I know more I will try to contribute more.
Anyways to my problem im having at the moment, im trying to search for a keyword, the keywords are stored in an array and also the strings that im searching through are exploded into an array for each line (each product is on a seperate line). Heres the main portion of the code which I need help with.
$contents = /* csv file which is being read */
$arr = explode("n",$contents);
$search = array
(
"ACCESS POINT",
"AUDIO EQUIPMENT",
"WEB CAMERA"
);
$result = "results.csv";
$fh = fopen($result, 'wa') or die("can't open file");
if ($search)
{
$i = 0;
$line = 1;
while ($i <= count($search))
{
if (strpos($arr[$line], $search[$i]) > 0)
{
$write = $arr[$line];
fwrite($fh, $write);
}
$line++;
$i++;
}
}
Ive altered it a bit to make it shorter but the part of it works when I have $search as a single keyword, however when I add the list of keywords into an array and count up using $search[$i] and $i++, it doesnt seem to search through the list of keywords for each line im searching through.
Any help or advice would be appriciated.
Thanks
No comments posted yet
Your Answer:
Login to answer
74
28
Other forums
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma
Sequre login with cookies.
I want to build secure login with cookies. I just want your ideas about this, your suggestions. What
On page view, minus credit
Hello all, please, I need a little help with this script. I am charging one credit (credits can be p
Default TimeZone
The server I'm working with is hosted in America so all times inserted into the database are coming
Show specific day of the week
I have been racking my brain trying to get this function to work properly and it is doing so for eve
Reduce redundancies in switch functions?
Hello all! I somewhat new to PHP, and was wondering if anyone could give some suggestions on a swit
Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi
word wrap in emails help needed
Hello, I understand how wordwrap works in php and have used it well before. However when I used wor
displaying email without attracting a ton of spam
Hello,
this is maybe the wrong place to ask.
How would you display an email address on a w
INSERT for date range
Hi all
I have the following table
Code: [Select] `date` date
`day` int(2)
`