Forum Moderators: coopster
The following works fine
$keywords = str_replace(array('x', 'y', 'z'), "", $keywords);
But I want to read the array in from a file. I cant seem to get it or find an example. I can get the file to echo to produce
x y z
Is there a simple way of doing this or do I have to print each time with 'array value', and then remove the trailing comma and then bung that variable into the above str_replace.
I have used the following to print to screen ok:
$filename = 'stopwords.txt';
$fp = fopen($filename, "r");
$stopwords = fread($fp, filesize($filename));
fclose($fp);
echo $stopwords;
Is the method I am trying to get to efficient or do I need to lok at another method.
TIA
The file [php.net] function reads an entire file into an array. Unfortunately it includes the end of line character as well which you would have to remove for each line.
$fp = @fopen($filename, 'r');
if ($fp) {
$array = explode("\n", fread($fp, filesize($filename)));
}
The code snippet above gives you an array without the end of line character.
Andreas
My abilities with php fall somewhat short and as a result I have trouble with the absolute basics at times. Take this case for example, cant get the swine to work......
The @ seems strange, but what do I know :)
So I am off to create a function with a big long list of words and get use a find and replace to put the ''s in. :(
$keywords = str_replace(array('x', 'y', ..... 'n', "", $keywords);
Cheers
So I am off to create a function with a big long list of words and get use a find and replace to put the ''s in.
I´m not quite sure that I get your point on this one.
Given a stop.txt file like this
aaron
nick
a string of keywords like this
tampa WebmasterWorld aaron sew sheffield
and a script like this
$filename = 'stop.txt';
$fp = @fopen($filename, 'r');
if ($fp) {
$array = explode("\n", fread($fp, filesize($filename)));
}
$keywords = str_replace($array, "", $keywords);
echo $keywords;
will give you
tampa WebmasterWorld sew sheffield
Andreas
I´m not quite sure that I get your point on this one.
I am still going to try and get to the bottom of it and thank you for your examples which should see me right. I like to be able to understand and do something myself even if it drives me up the wall. "It" has challenged me and I aint gonna give in.
Cheers