Eregi 对 preg_replace 进行更改以实现 php 5.3 兼容性

发布于 2024-09-15 21:40:33 字数 333 浏览 2 评论 0原文

我的一个脚本中有这一行,它抛出了一个已弃用的错误。

 eregi_replace( '\.([a-z]{3,4})$', "-{$width}x{$height}.\\1", $src );

有人可以告诉我如何将其转换为 preg_replace 并告诉我原因以及需要更改哪些部分,以便我可以了解未来的更改吗?我自己也尝试过,但是这段代码在哪里意味着它真的很难测试!

是否像纯粹用 preg_replace 替换 eregi_replace 一样简单?

我讨厌正则表达式:)

I have this line in one of my scripts and its throwing a deprecated error.

 eregi_replace( '\.([a-z]{3,4})

Can someone show me how to turn this into preg_replace and tell me why and which bits of it need to change so I can learn for future changes? I have had a go myself but where this bit of code is means its really hard to test!!

Is it as simple as purely replacing the eregi_replace with preg_replace?

I hate regular expressions :)

, "-{$width}x{$height}.\\1", $src );

Can someone show me how to turn this into preg_replace and tell me why and which bits of it need to change so I can learn for future changes? I have had a go myself but where this bit of code is means its really hard to test!!

Is it as simple as purely replacing the eregi_replace with preg_replace?

I hate regular expressions :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2024-09-22 21:40:33

您需要 分隔符,例如 /i 修饰符

/\.([a-z]{3,4})$/i

所以:

preg_replace('/\.([a-z]{3,4})$/i', "-{$width}x{$height}.\\1", $src);

请参阅此 POSIX ERE 和 PCRE 之间差异的手册页

You need delimiters like / and the i modifier:

/\.([a-z]{3,4})$/i

So:

preg_replace('/\.([a-z]{3,4})$/i', "-{$width}x{$height}.\\1", $src);

See this manual page for the differences between POSIX ERE and PCRE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文