Help - Search - Members - Calendar
Full Version: preg_replace() and Regex issues
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
Lang
Hey,

I'm having issues with my regex. My syntax seems to be fine as I tested it in a program called Regex Buddy and it worked great.

String to match
CODE
[action]=addItem,[player]=116, [zone]=5, [item_id]=45653, [item_cost]=35, [addItem]=1,


Regex
CODE
\[action\]\=addItem\,\[player\]\=([0-9]+)\,\s\[zone\]\=([0-9]+)\,\s\[item\_id\]=([0-9]+)\,\s\[item\_cost\]\=([0-9]+)\,\s\[addItem\]\=1\,


Error i'm getting

CODE
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash


My code

CODE
$l['log_what'] = trim($l['log_what']);
$addItem = preg_replace('\[action\]\=addItem\,\[player\]\=([0-9]+)\,\s\[zone\]\=([0-9]+)\,\s\[item\_id\]=([0-9]+)\,\s\[item\_cost\]\=([0-9]+)\,\s\[addItem\]\=1\,', '$1|$2|$3|$4', $l['log_what']);
$addItem = explode('|', $addItem);


Any help is greatly appreciated,
Lang
rc69
QUOTE
Delimiter must not be alphanumeric or backslash

CODE
$addItem = preg_replace('/\[action\]\=addItem\,\[player\]\=([0-9]+)\,\s\[zone\]\=([0-9]+)\,\s\[item\_id\]=([0-9]+)\,\s\[item\_cost\]\=([0-9]+)\,\s\[addItem\]\=1\,/', '$1|$2|$3|$4', $l['log_what']);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.