preg_match并删除字符

时间:2015-05-26 03:12:40

标签: php preg-replace

我有一个像

这样的字符串
https:\/\/scontent.xx.fbcdn.net\/hphotos-xta1\/v\/t1.0-9\/p50x50\/11139440_1010664825611559_1305796970308877058_n.jpg?oh=6da07776dd8ba8270c2c32de2957b7d3&oe=560D0AF0

我想用preg_replace函数替换所有“\” 就像这样

https://scontent.xx.fbcdn.net/hphotos-xta1/v/t1.0-9/p50x50/11139440_1010664825611559_1305796970308877058_n.jpg?oh=6da07776dd8ba8270c2c32de2957b7d3&oe=560D0AF0

示例:

  • https: // - > HTTPS:的 //
  • net / hphotos-xta1 / - >净/ hphotos-xta1 /

我如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

为什么要使用,之后stripslashes()会为你做这件事:

<强>结果:

https://scontent.xx.fbcdn.net/hphotos-xta1/v/t1.0-9/p50x50/11139440_1010664825611559_1305796970308877058_n.jpg?oh=6da07776dd8ba8270c2c32de2957b7d3&oe=560D0AF0

示例

<?php
$string = 'https:\/\/scontent.xx.fbcdn.net\/hphotos-xta1\/v\/t1.0-9\/p50x50\/11139440_1010664825611559_1305796970308877058_n.jpg?oh=6da07776dd8ba8270c2c32de2957b7d3&oe=560D0AF0';

echo stripslashes($string);