vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need a quick help regarding regular expression (P (https://vborg.vbsupport.ru/showthread.php?t=230867)

Jaffery 12-22-2009 06:08 PM

Need a quick help regarding regular expression (P
 
I need little help of any php programmer here for preg_replace.

What will be the regex to match following :
Code:

[img width=320 height=217]
Here value for width and height changes.

Actually I need it for cleaner.php , asking here as on vbulletin.com, there is not much help in this matter.

The Geek 12-22-2009 07:06 PM

Not 100% sure of what you're trying to do but this would grab the values from the above string:

\[img width=(\d*) height=(\d*)\]

so this:
PHP Code:

$subject '[img width=320 height=217]';
$find '/\[img width=(\d*) height=(\d*)\]/im';
$replace 'width=\1 and height=\2';
$result preg_replace($find$replace $subject); 

would give you:

width=320 and height=217

Jaffery 12-23-2009 05:28 AM

Using cleaner.php, I need to change all instances of [img width=320 height=217] to [img] in my forum which I recently converted from smf to vb.

I will try it and let you know.


btw, just asking as I am still understanding regex, what does widht=\1 and height width=\2 stands for. ie. \1 and \2 , what they denote ?

Thanx :)

Update: Thanx buddy, it helped.

The Geek 12-23-2009 07:35 AM

Quote:

Originally Posted by Jaffery (Post 1936099)
Using cleaner.php, I need to change all instances of [img width=320 height=217] to [img] in my forum which I recently converted from smf to vb.

I will try it and let you know.


btw, just asking as I am still understanding regex, what does widht=\1 and height width=\2 stands for. ie. \1 and \2 , what they denote ?

Thanx :)

Update: Thanx buddy, it helped.

in the regex I gave you, the first (\d*) goes into \1 and the second one goes into \2

Jaffery 12-28-2010 05:06 AM

I need little more help..

What would be regex to match following :
[youtube=425,350]

rather I need to convert :
Code:

[youtube=425,350]NN7XXCDqzVg[/youtube]
TO

Code:

[video]http://www.youtube.com/watch?v=NN7XXCDqzVg[/video]

ForumsMods 12-28-2010 06:24 AM

Use the following regular expressions:
Code:

/\[youtube=(.*)\](.*)\[\/youtube\]/im

Jaffery 12-28-2010 07:54 AM

That would match whole following..
Code:

[youtube=425,350]NN7XXCDqzVg[/video]
However, I need to grab value which is in bold and then
Put it in :
[code][video]http://www.youtube.com/watch?v=NN7XXCDqzVg[/video]

I can do following:
PHP Code:

$subject '[youtube=425,350]NN7XXCDqzVg[/youtube]';
$find '/\[youtube=(\d*){3},(\d*){3}\][a-zA-Z-]*\[/youtube]/im';
$replace '[video]http://www.youtube.com/watch?v=\3[/video]';
$result preg_replace($find$replace $subject); 

Now kindly advice if that is ok as I am still not confident in regex and had hardly used backreference before.

ForumsMods 12-28-2010 02:21 PM

Use this:
PHP Code:

$subject '[youtube=425,350]NN7XXCDqzVg[/youtube]';
$find '/\[youtube=(.*)\](.*)\[\/youtube\]/im';
$replace '[video]http://www.youtube.com/watch?v=\2[/video]';
$result preg_replace($find$replace $subject); 



All times are GMT. The time now is 11:48 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.01103 seconds
  • Memory Usage 1,735KB
  • 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
  • (5)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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