gpt4 book ai didi

php - 如何使用 PHP ereg_replace 替换所有特定字符?

转载 作者:行者123 更新时间:2023-12-04 21:18:14 25 4
gpt4 key购买 nike

我想在 PHP 上使用正则表达式将特定符号替换为符号 %。例如。

$result = ereg_replace('xlp','%','example')`. //$result = `'e%a%%me'

这是可能的还是我应该使用其他方式?

最佳答案

首先,关于 ereg_replace :

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

改用preg_replace

接下来,在您的模式中,您要搜索文字字符串 xlp。将它们放在一个字符集中以匹配三个中的一个

$result = preg_replace(
"/[xlp]/",
"%",
$string
);

关于php - 如何使用 PHP ereg_replace 替换所有特定字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33537697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com