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...

Recommended Answers

All 6 Replies

Member Avatar for diafol

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)?

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

Member Avatar for diafol

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);

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

thanks again

Member Avatar for diafol

Ok solved?

yep and marked accordingly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.