Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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