Jump to content


preg_replace() and Regex issues


1 reply to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 June 2009 - 09:09 PM

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
[action]=addItem,[player]=116, [zone]=5, [item_id]=45653, [item_cost]=35, [addItem]=1,

Regex
\[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

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

My 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

Edited by Lang, 19 June 2009 - 09:18 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 June 2009 - 10:17 AM

Quote

Delimiter must not be alphanumeric or backslash
$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']);

Edited by rc69, 20 June 2009 - 10:17 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users