vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What am I doing wrong with this preg_match? (https://vborg.vbsupport.ru/showthread.php?t=206277)

DISLEX 02-22-2009 10:56 PM

What am I doing wrong with this preg_match?
 
I'm working on a plugin and I'm trying to pull out quotes from a post message ($post[pagetext]). For some reason, it works if there's a quote->img->/img->/quote combination, but if there is any text inside the quote WITH an image, it won't pick it up.

here's my regex: $qc = preg_match_all("/(\[quote)(.*)(\[\/quote\])/i", $post[pagetext], $quotematches, PREG_SET_ORDER);

here are some examples of the regex results:

Quote:

Originally Posted by example post where $qc = 1
Quote:

Originally Posted by user
hey!

hey, how's it going?

In the above, it would detect the quoted message by "user"

Quote:

Originally Posted by another example where $qc = 1
Quote:

Originally Posted by user2

oh cool I'm not color blind

in the above, it still detects the quote

HOWEVER, in the following:

Quote:

Originally Posted by example where $qc = 0
Quote:

Originally Posted by user2
Look at this, if you can't see the '5' you might be colorblind!
https://vborg.vbsupport.ru/

oh cool I'm not color blind

it doesn't detect the quote. I've noticed that it doesn't catch a quote if there's text AND an image inside of the quote. How on earth is that not a match?

hambil 02-23-2009 01:56 AM

I think you are forgetting to deal with the new line between the text and the image

Dismounted 02-24-2009 04:50 AM

Have a look at how vBulletin finds quotes in strip_quotes().

DISLEX 03-03-2009 09:40 PM

Quote:

Originally Posted by hambil (Post 1751943)
I think you are forgetting to deal with the new line between the text and the image

does (.*) not match newlines?

Dismounted 03-05-2009 05:08 AM

You need to add a PCRE modifier for it to count new lines as well. IIRC, the modifier is m. However, you should still be using vBulletin's method of detecting quotes, as it does not use costly regex functions.

DISLEX 03-05-2009 10:51 PM

Quote:

Originally Posted by Dismounted (Post 1760804)
You need to add a PCRE modifier for it to count new lines as well. IIRC, the modifier is m. However, you should still be using vBulletin's method of detecting quotes, as it does not use costly regex functions.

it says that if there are no start-of-line (^) or end-of-line ($) modifiers, then 'm' has no effect:

http://us2.php.net/pcre.pattern.modifiers

TigerC10 03-05-2009 10:57 PM

No, you add the m modifier at the end, next to the i for case insensitive matches. Kind of like the g modifier (makes it "global", which matches more than one on a single line)...


All times are GMT. The time now is 01:14 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01078 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete