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 11-22-2004, 04:46 AM
Michael Morris's Avatar
Michael Morris Michael Morris is offline
 
Join Date: Nov 2003
Location: Knoxville TN
Posts: 774
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default HELP PLEASE!! Help with preg_replace

Hello all. I'm working on the following replacement routine in my PHP Include end (no, I'm not allowed to hack the bbcodeparser)

I'm getting this error

Parse error: parse error, expecting `'('' in /web/boards/includes/functions.php(1932) : eval()'d code(36) : regexp code on line 1

Fatal error: Failed evaluating code: str_ireplace(Array, Array, 'WBURG'); in /web/boards/includes/functions.php(1932) : eval()'d code on line 36

here's the code

PHP Code:
//################ Do Mana Cost tag ######################

// Valid Characters to search for
$mana_find = array( 'w','u','b','r','g','t','x','y','z','1','2','3','4','5','6','7','8','9','0');

// Replacement Strings to insert
$mana_replace = array( 
    
'<img src="http://www.wizards.com/images/symbols/Symbol_W_mana.gif" border="0" alt="W" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_U_mana.gif" border="0" alt="U" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_B_mana.gif" border="0" alt="B" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_R_mana.gif" border="0" alt="R" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_G_mana.gif" border="0" alt="G" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_T_mana.gif" border="0" alt="T" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_X_mana.gif" border="0" alt="X" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_Y_mana.gif" border="0" alt="Y" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_Z_mana.gif" border="0" alt="Z" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_1_mana.gif" border="0" alt="1" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_2_mana.gif" border="0" alt="2" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_3_mana.gif" border="0" alt="3" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_4_mana.gif" border="0" alt="4" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_5_mana.gif" border="0" alt="5" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_6_mana.gif" border="0" alt="6" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_7_mana.gif" border="0" alt="7" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_8_mana.gif" border="0" alt="8" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_9_mana.gif" border="0" alt="9" />',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_0_mana.gif" border="0" alt="0" />'
    
);
    
// Now for the fun part - first we define our tag.
$manastring_find '#\[mctwo\](.*)\[/mctwo\](<br />|<br>)??#esiU';

// Now we define our replacement
$manastring_replace "str_ireplace($mana_find$mana_replace, '\\1');";

// Cross our fingers. 
$output preg_replace($manastring_find$manastring_replace$output); 
Reply With Quote
  #2  
Old 11-24-2004, 05:05 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

change
PHP Code:
$manastring_replace "str_ireplace($mana_find$mana_replace, '\\1');"
into

PHP Code:
$manastring_replace 'str_ireplace($mana_find, $mana_replace, "\1");'
variables are already inserted when you use " but not when '
Reply With Quote
  #3  
Old 11-25-2004, 11:39 PM
Michael Morris's Avatar
Michael Morris Michael Morris is offline
 
Join Date: Nov 2003
Location: Knoxville TN
Posts: 774
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Xenon, you're change yielded this parse error

Code:
Parse error: parse error, expecting `'('' in /web/boards/includes/functions.php(1932) : eval()'d code(36) : regexp code on line 1

Fatal error: Failed evaluating code: str_ireplace(Array, Array, ''); in /web/boards/includes/functions.php(1932) : eval()'d code on line 3
Reply With Quote
  #4  
Old 11-26-2004, 12:08 AM
Michael Morris's Avatar
Michael Morris Michael Morris is offline
 
Join Date: Nov 2003
Location: Knoxville TN
Posts: 774
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, this works - sorta

PHP Code:
$output preg_replace("#\[mctwo\](.*)\[/mctwo\]#siU""str_ireplace($mana_find$mana_replace, '\\1');"$output); 
But it doesn't parse the str_ireplace. THE SECOND I put the 'e' parameter in for evaluation, it starts whining about a missing '(' character again.

This is pissing me off REAL bad.
Reply With Quote
  #5  
Old 11-26-2004, 02:50 AM
Michael Morris's Avatar
Michael Morris Michael Morris is offline
 
Join Date: Nov 2003
Location: Knoxville TN
Posts: 774
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm almost there, but I have one remaining problem. Here's my code

PHP Code:
//################ Do Mana Cost tag ######################

// Valid Characters to search for
$mana_find = array( "W""U""B""R""G""T""X""Y""Z""1""2""3""4""5""6""7""8""9""0");

// Replacement Strings to insert
$mana_replace = array(
    
'<img src="http://www.wizards.com/images/symbols/Symbol_W_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_U_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_B_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_R_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_G_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_T_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_X_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_Y_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_Z_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_1_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_2_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_3_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_4_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_5_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_6_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_7_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_8_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_9_mana.gif">',
    
'<img src="http://www.wizards.com/images/symbols/Symbol_0_mana.gif">'
    
);
    
// Now for the fun part - first we define our tag.
$manastring_find "#\[mctwo\](.*)\[/mctwo\]#esiU";

// Cross our fingers.
$output preg_replace($manastring_find'str_replace($mana_find, $mana_replace, $1)'$output); 
My problem is that the prereq is now searching the string twice. I'd like to be able to have border="0" alt="X" in the img name, and be able to include lower case w, u, b, r, g, x, y, z, and t; but when I do the thing screws up royally because it tries to replace those characters whereever they occur within the img tag. This sets up an infinite loop.

How do I stop it from searching through the string twice?
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 04:27 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03839 seconds
  • Memory Usage 2,232KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_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