[英]PHP Remove spaces and %20 within single function
我希望從字符串中刪除空格。 該字符串之前應該是urlencoded()
,所以我也希望刪除%20
。 我可以使用兩個單獨的功能執行此操作,但是如何使用一個功能執行此操作?
$string = str_replace("%20","",$string);
$string = str_replace(" ","",$string);
您可以使用preg_replace
函數。
preg_replace('~%20| ~', "", $string)
請勿使用正則表達式,而應使用strtr:
$result = strtr($str, array('%20'=>'', ' '=>''));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.