PHP删除字符串中的字符 [英] PHP removing a character in a string

查看:146
本文介绍了PHP删除字符串中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP很弱,我正在尝试更改此字符串:

My php is weak and I'm trying to change this string:

http://www.example.com/backend.php?/c=crud&m=index&t=care
                                   ^

成为:

http://www.example.com/backend.php?c=crud&m=index&t=care
                                  ^

backend.php?之后删除/.有什么最佳方法的想法吗?

removing the / after the backend.php?. Any ideas on the best way to do this?

谢谢!

推荐答案

我认为最好只使用 str_replace ,如手册​​中所述:

I think that it's better to use simply str_replace, like the manual says:

如果您不需要花哨的替换 规则(例如正则表达式), 应该始终使用此功能 而不是ereg_replace()或 preg_replace().

If you don't need fancy replacing rules (like regular expressions), you should always use this function instead of ereg_replace() or preg_replace().

<?
$badUrl = "http://www.site.com/backend.php?/c=crud&m=index&t=care";
$goodUrl = str_replace('?/', '?', $badUrl);

这篇关于PHP删除字符串中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆