Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2009, 06:08 PM
Jaffery Jaffery is offline
 
Join Date: Dec 2009
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 12-22-2009, 07:06 PM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 12-23-2009, 05:28 AM
Jaffery Jaffery is offline
 
Join Date: Dec 2009
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 12-23-2009, 07:35 AM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaffery View Post
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
Reply With Quote
  #5  
Old 12-28-2010, 05:06 AM
Jaffery Jaffery is offline
 
Join Date: Dec 2009
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]
Reply With Quote
  #6  
Old 12-28-2010, 06:24 AM
ForumsMods ForumsMods is offline
 
Join Date: Aug 2007
Location: Argentina
Posts: 667
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use the following regular expressions:
Code:
/\[youtube=(.*)\](.*)\[\/youtube\]/im
Reply With Quote
  #7  
Old 12-28-2010, 07:54 AM
Jaffery Jaffery is offline
 
Join Date: Dec 2009
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 12-28-2010, 02:21 PM
ForumsMods ForumsMods is offline
 
Join Date: Aug 2007
Location: Argentina
Posts: 667
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:18 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.04226 seconds
  • Memory Usage 2,240KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete