php - 替换多个正斜杠

标签 php

我想用一个正斜杠替换多个正斜杠。

例子:

this/is//an//example -> this/is/an/example

///another//example//// -> /another/example/

example.com///another//example//// -> example.com/another/example/

谢谢!

编辑:这将用于修复具有多个正斜杠的 URL。

最佳答案

试试

preg_replace('#/+#','/',$str); 

preg_replace('#/{2}#','/',$str);

提示:使用str_replace对于这样一个简单的替换它

replace all occurrences of the search string with the replacement string

str_replace('/','/',$str);

Reference

关于php - 替换多个正斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631017/

相关文章:

php - Mysql定义一个列名,由子内部查询从其他表中选择

php - 用字形替换颜色代码

php - WooCommerce 以编程方式创建订单并重定向到付款

php - 带有 php 循环的 CSS onmouseover 画廊

javascript - AJAX:动态更改第二页的内容

php - HTML 表单不发送 $_POST 值

关于mysqli的PHP继承

php - 通过 AJAX 传递希伯来语编码文本 (windows 1255)

php - 通过PHP上传SQL转储文件错误

php - 如何扩展 Zend Framework 应用程序以允许 RESTful 身份验证?