Jump to content


Photo

How do you convert POSIX patterns to PCRE?


  • Please log in to reply
1 reply to this topic

#1 Banshee

Banshee

    One Vision, One Purpose!

  • Network Admins
  • 9,045 posts
  • Location:Rio De Janeiro, RJ, Brazil.
  • Projects:PPM, PPM: Final Dawn, OS SHP Builder, OS Palette Editor, OS W3D Viewer, VXLSE III, etc...
  •  Retired Network Leader
  • Division:Revora
  • Job:Maintenance Admin

Posted 21 February 2010 - 03:56 AM

This server was recently upgraded with PHP 5.3.0 and all functions that uses POSIX patterns (like eregi_replace) are being deprecated. So, I have this piece of code:


$msg = eregi_replace("[^\"\'\=](http|https|ftp|ftps|mailto|torrent)://([$ACCEPT_CHARS]+)", "<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>", $msg);


I know that I have to use preg_replace instead of eregi_replace, but preg_replace requires a PCRE pattern and I don't know the difference between both patterns (I know nothing about POSIX, to be honest). So, I've simply tried to change eregi_replace to preg_replace and PHP complained at the '('.


[21-Feb-2010 01:48:09] PHP Fatal error: Uncaught exception 'ErrorException' with message 'preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier '('' in



Any ideas?
Project Perfect Mod

Command & Conquer Mods, Mods Support, Public Researchs, Map Archives, Tutorials, Tools, A Friendly Community and much more. Check it out now!

Posted Image

#2 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 21 February 2010 - 11:31 AM

PCRE's are like this:

<delimiter><pattern><delimiter><modifiers>

The delimiter can be any character not used in the pattern, e.g:

/^[a-z]+$/i

(i is the case-insensitive modifier)
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users