I'm using a downloaded PHP script to speed up development of my site, but I'm having a stack of 'deprecated' messages coming up relating to ereg. I'm going to turn off warnings before going live, but am trying to make sure I clear them all first!
I found a handy guide which is good for the simple bits, such as changing eregi_replace for preg_replace with / and /i but I'm running into problems with some of the more advanced expressions (with comments, concatenation, variables, braces and more - some are the same types, but I'm getting so confused trying and breaking it!).
Can anyone tell me where I should put the / or / /i when I update the following, or, just as welcome, tell me what do do with each type (or point me at instructions) so I can do it myself?
eregi("<!--\ startBlock\(([^)]+)\)\ -->", $content["body"], $m)
eregi($reg, $content["body"], $m)
eregi("([^\.]+)\.(.*)", $variable, $m) ... I think (?) this is preg_replace("/([^\.]+)\.(.*)/i", $variable, $m)
eregi("{url:([^}]+)}", $txt, $m))
eregi_replace("{".$key."}", $val, $txt)
eregi_replace("{script}", $HTTP_SERVER_VARS["SCRIPT_NAME"], $txt)
eregi_replace("{ifNotSet:".$m[1].":([^}]+)}", "", $txt)
Update: I seem to have it all working (thanks for the help) except one function below, where I can't figure out the preg versions - I have tried various combinations but the resulting page never gives the same result as the eregi version (with the error line). Any suggestions?
function parse(&$content) {
while (preg_match("/<!--\ startBlock\(([^)]+)\)\ -->/i", $content["body"], $m)) {
$name = $m[1];
$block = array();
$block["name"] = $name;
$block["blocks"] = array();
$block["used"] = 0;
$block["values"] = array();
$reg = "<!--\ startBlock\(".$name."\)\ -->(.*)<!--\ endBlock\(".$name."\)\ -->";
if (!eregi("$reg", $content["body"], $m)) {
$this->error("block `".$name."' does not have startBlock() AND endBlock().");
}
$block["body"] = $m[1];
$content["body"] = eregi_replace("$reg", "{".$name."}", $content["body"]);
$content["blocks"][$name] = array();
$this->parse(&$block);
$content["blocks"][$name][0] = $block;
}
}
and then I'll get started on the "call-time pass-by references", which seem even trickier!