简体   繁体   English

如何使用正则表达式从URL中删除“&”符号?

[英]How do I remove a “&” symbol from a URL using regular expressions?

how to remove a & Symbol from a url address use php regular? 如何使用php常规从URL地址中删除&符号? for example: http://www.google.com/search?hl=en&q=php left the & and get : http://www.google.com/search?hl=enq=php Thanks 例如: http://www.google.com/search?hl=en&q=php : http://www.google.com/search?hl=enq=php zh_CN & q http://www.google.com/search?hl=enq=php php离开了&并获得了: http://www.google.com/search?hl=enq=php : http://www.google.com/search?hl=enq=php zh_CN http://www.google.com/search?hl=enq=php php谢谢

$url = 'http://www.google.com/search?hl=en&q=php';
$url = str_replace('&', '', $url);

I'm not sure I really understand the question. 我不确定我是否真的理解这个问题。 It sounds like you just want to remove & characters. 听起来您只想删除&字符。 That can be easily done: 可以很容易做到:

$url = str_replace('&', '', $url);

You can remove it easily enough with str_replace. 您可以使用str_replace轻松删除它。 Why you would want to do this, however, is another matter entirely. 但是,为什么要执行此操作完全是另一回事。

Are you trying to insert a URL into a page with PHP and getting validation errors due to the & symbol? 您是否正在尝试使用PHP将URL插入页面并由于&符号而导致验证错误? In that case urlencode() might be what you really need. 在这种情况下,您可能真正需要urlencode()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM