Link to home
Create AccountLog in
Avatar of pj64
pj64

asked on

ereg_replace help

ereg_replace is now depricated, I have a script that uses this function and I now need to update to preg_replace.

giving this error  "Warning: preg_replace(): Unknown modifier 'F' in ...on line 64"

//$_R=ereg_replace('__FILE__',"'".$_F."'",$_X);

$_R=preg_replace('__FILE__',"'".$_F."'",$_X); it makes no sense to delimit the variable or the concatenation.

Anyone know what the issue is?
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

preg_replace requires pattern delimiters:

$_R=preg_replace('/__FILE__/',"'".$_F."'",$_X); 

Open in new window

Please use the code snippet to post code at EE -- it gives us unispace fonts and line numbers, and makes it easier to discuss the issues.
Most of the time you can just do what TerryAtOpus suggests - just add the regex delimiter as the first and last character of the expression.  In the case of your script, the use of '__FILE__' had the effect of telling the regular expression engine that the underscore was the regex delimiter.  I'm quite sure the engine was confused by seeing it several times in the expression!

Not suggesting that you make this part of your long-term planning, but you can add this to the top of your scripts.

error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);

Some docs that may help you with the changes...
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
http://www.php.net/manual/en/function.preg-match.php
http://www.php.net/manual/en/function.preg-replace.php
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
Avatar of pj64
pj64

ASKER

@TerryAtOpus: that gives: "Warning: preg_replace(): Unknown modifier '_'" so it is a bit more that that unfortunately.

@Ray_Paseu: thanks did not see it but in future I will make sure I do.

thanks for the url's I will look at them later today as time allows., I'm guessing it may be the
',"'"

Open in new window

in the middle that my be the issue, but I am not sure which one regex is not really my thing.
Avatar of pj64

ASKER

Should be simple but I have not had much sleep lately. Took me way to long to find a simple error in something else, because I forgot I was not looking at a wordpress script and the closing div was not where I expected it to be.  So I figured this time I would ask until I get past sleep depro.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of pj64

ASKER

ta, that worked fine. I also just did a plain str_replace and that worked also.
Avatar of pj64

ASKER

fast and accurate