Hi,
I need some helt please! I am stuck in this foreach loop.
What I am trying to do, is to match substrings of the lines in a text file, and then for all the matching lines store a substring in an array. This substring should both be printet on the screen, and used later outside the foreach loop.
The text file has the following format:
a_first_word,a_word,some_other_inf
a_second_word,a_word,some_other_inf
a_third_word,a_word,some_other_inf
b_first_word,b_word,some_other_inf
b_second_word,b_word,some_other_inf
b_third_word,b_word,some_other_inf
etc ...
if(!isset($_POST['searchterm']))
echo'';
else{
$word = $_POST['earchterm'];
$lines = file("./list.dic");
$matches = preg_grep("/(.*),$word\.(.*)/", $lines);
$searchstring = array();
foreach($matches as $line){
preg_match("/^(.+),.*\..*/s",$line,$wordforms);
$searchstring = $wordforms[1];
echo " $searchstring";
}
}
$komma_separated = implode(',',$searchstring);
echo " $komma_separated"
[code]
The 'echo "$searchstring" works as a charm: when the user inputs 'a_word', then this is printed
'a_first_word a_second_word
a_third_word'
However, the stuff outside the loop doesnt work :(, and I get this warning:
Warning: implode() [function.implode]: Bad arguments. in c:\program files\apache group\Apache\htdocs\mit_forsoeg_google_results.php on line 71
I have tried 'everything' (including 'serialize' instead of 'implode'), and nothing seems to work. If i skip the implode part, I only get the last element in the array, so that is no good...
I have also tried putting the implode part inside the loop, but that didn't work either - I got the same warning. I have tried using implode in a test file with nothing else in it, and here it works without warnings!
What is wrong???
ANY help would be highly appreciated :)
-Pinkerbot