Jump to content

Find any questions in strip_tagged($Web_Page)?


amedhussaini

Recommended Posts

Trying to search a $string (just an HTML page grabbed with curl after stripping the tags) for questions.  I thought to look to return content between "What" and "?" inclusive, etc... but no luck so far.

 

Valid questions I'm looking for:

 

"What is the point?"

"what is the point?"

 

I'd like the function to return all results into an array if possible

 

Cheers,

Amed

newbtophp, I think that will match more than what he wants. Also, maybe preg_match_all would be more useful.

 

What if you have this - "I wonder what he would do after this fails. Do you think think he'll jump off a building?" Try your regexp against that string. Or this one - "Geez, whatever man. Just stop yelling at me. Did I do something that offended you?"

 

I would try:

preg_match_all("#\W\s(?<questions>What [^!?\.]+\?)#i", $str, $results);

Thanks!  This works like a charm.  Ran it on a few test cases... 99% were accurate, came up with a few of these:

 

: What is RSS? )

 

What is the WTO? )

 

Any ideas on further refining it?

 

For now, I will study your regex expression and decipher how you came up with it... this place really is a wealth of knowledge

 

newbtophp, I think that will match more than what he wants. Also, maybe preg_match_all would be more useful.

 

What if you have this - "I wonder what he would do after this fails. Do you think think he'll jump off a building?" Try your regexp against that string. Or this one - "Geez, whatever man. Just stop yelling at me. Did I do something that offended you?"

 

I would try:

preg_match_all("#\W\s(?<questions>What [^!?\.]+\?)#i", $str, $results);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.