替换 ereg_replace
可能的重复:
如何在 PHP 中将 ereg 表达式转换为 preg?< /a>
我已经升级了 php,现在收到了 ereg_replace
已弃用错误。
我在网上做了一些搜索,发现我可以使用 preg 代替,但不确定如何正确更改此代码
$scriptName = ereg_replace(
"^".$_SERVER["DOCUMENT_ROOT"], "",
$_SERVER["SCRIPT_FILENAME"]
);
Possible Duplicate:
How can I convert ereg expressions to preg in PHP?
I have upgraded php and now im getting the ereg_replace
deprecated errors.
I have done some searching round web and found that I can use preg instead but not sure how to change this code correctly
$scriptName = ereg_replace(
"^".$_SERVER["DOCUMENT_ROOT"], "",
$_SERVER["SCRIPT_FILENAME"]
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
e
替换为p
。在第一个参数的开头和结尾添加分隔符。传统上,人们使用斜杠 (
/
),但我喜欢使用~
,因为在正则表达式中实际使用该字符的机会较少。Replace the
e
with ap
.Add a delimiter to the beginning and end of that first argument. Traditionally, people use slashes (
/
), but I like to use~
as there is less chance of actually using that character in the regular expression.当 $_SERVER["DOCUMENT_ROOT"] 的值中包含特殊字符时,仅添加分隔符将不起作用。您需要按如下方式转义它们:
Just adding delimiters won't work when special characters are included in $_SERVER["DOCUMENT_ROOT"]'s value. You need to escape them as follows: