【问题标题】:how to remove speacial character like: & ) ( \ / from the string using php?如何使用php从字符串中删除特殊字符,例如:&)(\ /?
【发布时间】:2017-08-01 17:02:06
【问题描述】:

如何从脚本中删除/转义特殊字符

字符串是

echo $position="marketing & executive cum \ stock ";

Outputs are: marketing & executive cum \ stock

但我想要删除后的结果:

output: marketing executive cum stock

怎么可能?

有什么解决办法请帮忙..

【问题讨论】:

标签: php html mysql


【解决方案1】:

此问题可能与此问题重复 Remove all special characters from a string 所以请删除这个问题

【讨论】:

    【解决方案2】:

    通过使用 preg_replace() 你可以做到这一点

    function cleanString($string) {
       $string = str_replace(array( '(', ')' ), '', $string);
       return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string); 
    }
    
    echo cleanString('marketing & executive cum \ stock ');
    

    【讨论】:

    • 感谢它的作品,但我想删除)(这些也请建议..
    • @Muthu17 :这会很棒:eval.in/752861 获得单个空格
    • @Niklesh 好一个。这会有所帮助
    【解决方案3】:

    使用关注

    $position="marketing & executive cum \ stock ";
    
    echo preg_replace('/[^A-Za-z0-9\-\(\) ]/', '', $position);
    

    【讨论】:

    • 它可以工作,但想删除)(也是如此,它是如何可能的
    • preg_replace('/[^A-Za-z0-9\-]/', '', $position);
    猜你喜欢
    • 2012-05-30
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多