0

Hi all, hope you are having a better day than I am...

I am trying to write the results of a search of text using preg_match_all to a database...

First thing I need to do is write the results of the search to an array (which preg_match_all does)... It writes the results to a two dimensional array... WHICH IS GOOD...

However I am struggling to return the results in that array (ie the returned values, not the keys), but with zero luck - WHICH IS BAD...

below is the code that I am using, but does not seem to want to work...

preg_match_all('/(?!\b)(#\w+\b)/',$tDescrip,$foundKeywords);
foreach($foundKeywords as $value)
{
    echo "Keyword:$value?\n";
}

Any ideas as to what I am doing wrong?

Thanks in advance...

2
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by mktrx
0

We'd have a better idea if you tried to explain what you hope to achieve from the regex pattern and an example of text help in the $tDescrip variable. For example does the var contain multilines (i.e \n)?

0

Thanks diafol

Intent is to capture any words that start with a hashtag (#) and write them as seperate records in a database... The var will have multilines...

Hope this helps...

Ian

0

The s modifier may be overkill, but this seems to work for me:

$txt = "#me #prob #see #lemon
#hello #free";

preg_match_all('/(#\w+\b)/s',$txt,$k);

print_r($k);
0

Thanks diafol managed to sort it out... User input error on my part (no suprise there) ;-)

thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.