如何替换\成/

来源:2-5 正则表达式函数之preg_replace与preg_filter

dd12

2016-01-19 22:14

D:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\www\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\dunling   替换成D:\www\dunling   谢谢

写回答 关注

1回答

  • 万石以磨而锋
    2016-01-20 10:43:59

    $pattern = "/\\\+/";

    $replacement = '\\';

    $str = 'D:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\www\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\dunling';
    //$str = stripcslashes($str);
    $result = preg_replace($pattern,$replacement,$str);
    var_dump($result);

鬼斧神工之正则表达式

以PHP语言为蓝本,介绍正则表达式的基本语法以及他的强大用处

47865 学习 · 113 问题

查看课程

相似问题