We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,289 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

preg_match_all is doing my head in

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
1 Day
Discussion Span
7 Months Ago
Last Updated
7
Views
Question
Answered
mktrx
Newbie Poster
6 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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)?

diafol
Keep Smiling
Moderator
10,665 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

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

mktrx
Newbie Poster
6 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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);
diafol
Keep Smiling
Moderator
10,665 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

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

thanks again

mktrx
Newbie Poster
6 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Ok solved?

diafol
Keep Smiling
Moderator
10,665 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57
Question Answered as of 7 Months Ago by diafol

yep and marked accordingly

mktrx
Newbie Poster
6 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0809 seconds using 2.76MB