简体   繁体   English

使用preg_replace()从字符串中删除'%'

[英]Remove '%' from string using preg_replace()

How do I remove % from a string using preg_replace function? 如何使用preg_replace函数从字符串中删除

Here is what I currently have, but the % sign is blocking the twitter share button from processing: 这是我目前拥有的东西,但是%符号阻止了twitter共享按钮的处理:

<div class="twitter">
<a href="http://twitter.com/share?text=Just%20Sorc\'d:%20%20'. preg_replace('/((?:http|https|ftp):\/\/(?:[A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?[^\s\"\']+)/i','<a href="$1" rel="nofollow" target="blank">$1</a>',$post).'%20--%20via:%20%20http://www.sorcd.com/'.$session_user_id.'%20%20at%20%20" target="_blank" data-count="none"><img src="https://abs.twimg.com/a/1378977615/images/resources/twitter-bird-white-on-blue.png" width="16px" alt="Tweet"></a>
</div>

Firstly, Your string/URL has URI encoded values like %20 which means they are spaces. 首先,您的字符串/ URL具有URI编码的值,例如%20,这意味着它们是空格。 Removing % will not solve the problem. 删除%不会解决问题。

Secondly, this is a possible duplicate of how-to-remove-sign-in-php-string . 其次,这可能是如何删除php-string的副本。

You can use urldecode() to decode it. 您可以使用urldecode()对其进行解码。 '%20' means space '%20'表示空格

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

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