doumei9589 2017-04-05 20:14
浏览 26

如何用另一个特殊字符替换php中的特殊字符'/'

How to replace special character '/' in a string in php. I just want replace only this special character, not all special character

For eg,

$str= 3/26, 5/15, 5/20, 5/26-5/28;

I want to replace / with -.

I want to replace'/' with something as passing this string to form a xml is giving error.

  • 写回答

2条回答 默认 最新

  • dqy0707 2017-04-05 20:15
    关注

    You would use str_replace(search, replace, subject)

    ex:

    $str = '3/26, 5/15, 5/20, 5/26-5/28';
    $str = str_replace("/", '-', $str);
    

    outputs:

    3-26, 5-15, 5-20, 5-26-5-28

    评论

报告相同问题?