vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   HELP PLEASE!! Help with preg_replace (https://vborg.vbsupport.ru/showthread.php?t=72030)

Michael Morris 11-22-2004 04:46 AM

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


Xenon 11-24-2004 05:05 PM

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 ' :)

Michael Morris 11-25-2004 11:39 PM

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


Michael Morris 11-26-2004 12:08 AM

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.

Michael Morris 11-26-2004 02:50 AM

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?


All times are GMT. The time now is 11:06 AM.

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.03666 seconds
  • Memory Usage 1,754KB
  • 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
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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