views:

39

answers:

2

I'm writing this quick script to extract chatroom names from the source of a webpage. I'm grabbing the data with fopen() and fgets() and that all returns fine.

My regex is /#[a-zA-z]+/, which does seem to work. However I can not get preg_match_all() to return a concise list of data.

preg_match_all("/#[a-zA-z]+/", $contents, $foo, PREG_SET_ORDER);
foreach($foo as $item) print $item;

Returns "ArrayArrayArrayArrayArrayArrayArrayArray...".

print_r ($item);

Returns something along ( [0] => #channel1 ) Array ( [0] => #channe2 ) Array ( [0] => #channel3 )...

I'm unsure how to get this formated properly, any quick help?

+1  A: 
$contents = '#channel1 #channel2 #channel3';

preg_match_all("/(#[a-zA-z0-9]+)/", $contents, $foo, PREG_SET_ORDER);
var_dump($foo);
echo '<hr />';

foreach($foo as $item)
   print $item[1].'<br />';
Mark Baker
Still nothing. It just prepends each value of the the array with `string[strlength of value]`
Francis
Show us the value of $contents and how you want the output to look
Mark Baker
A: 

Walked away and came back and it was pretty clear what was up. The desired values in the $foo array were wrapped in another array. I simply wrapped my foreach() statement with another foreach() statement thusly:

foreach($foo as $item) {
   foreach($item as $bar) {
     print $bar . "<br />";
   }
}

Worked without a hitch.

Francis