gpt4 book ai didi

php - 从php中的字符串中转义特殊字符

转载 作者:行者123 更新时间:2023-12-05 08:34:04 26 4
gpt4 key购买 nike

我们正试图从我们的字符串中转义一些特殊字符请告诉我我们必须使用的函数例如HTC Desire 210 – 白色
在此示例中,我们转义 -(连字符)特殊字符。在上面的示例中,我们有很多具有不同特殊字符的产品名称,我们将其转义。感谢您的合作。

最佳答案

在此函数中传递字符串。

function clean($string){
$string = str_replace(' ', '-', $string); // Replaces spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}

有关更多信息,请查看此 Remove Special Character - Stackoverflow

关于php - 从php中的字符串中转义特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33011956/

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