2014-12-26 245 views
3

我有一個WordPress頁面有特殊字符

$str = 's.aspx?sm=Q830I7SJZvuSP3HzDfFlVA%3d%3d'; 

printf('<a href="https://www.surveymonkey.com/.urlencode($str)." target="_blank"> 
      <img src="http://www.anyfood.gr/net/wp-content/uploads/2014/12/evaluation2.jpg" style="padding:20px;"> 
     </a>' 
); 

但鏈接不起作用此PHP代碼的PHP腳本的URL,我已經用單引號試了幾個可能的招數,等等 但我可以想不出來...有什麼想法?

+0

或者試試這個'htmlspecialchars($ str);' –

+0

@ marilena6我想你忘了標記一個答案作爲正確的答案。 – tomloprod

回答

2

當訪問GET參數時,通常不需要使用urldecode()。使用它作爲如下:

$str = 's.aspx?sm=' . urlencode ('Q830I7SJZvuSP3HzDfFlVA%3d%3d'); 

echo '<a href="https://www.surveymonkey.com/'.$str.'" target="_blank"> 
     <img src="http://www.anyfood.gr/net/wp-content/uploads/2014/12/evaluation2.jpg" style="padding:20px;"> 
    </a>'; 
1
$str = 's.aspx?sm=Q830I7SJZvuSP3HzDfFlVA%3d%3d'; 

printf(' 
*<*a href="https://www.surveymonkey.com/".urlencode($str) target="_blank"> 
    *<*img src="http://www.anyfood.gr/net/wp-content/uploads/2014/12/evaluation2.jpg" style="padding:20px;"> 
    </a> 
'); 

**刪除*在錨標記和圖像標記**

1

的出發試試這個,它的工作對我來說:

<?php 
$str = 's.aspx?sm=Q830I7SJZvuSP3HzDfFlVA%3d%3d'; 

printf('<a href="https://www.surveymonkey.com/%1$s " target="_blank"> <img src="http://www.anyfood.gr/net/wp-content/uploads/2014/12/evaluation2.jpg" style="padding:20px;"> </a>', urlencode($str)); 
?> 
1
$str = 's.aspx?sm=Q830I7SJZvuSP3HzDfFlVA%3d%3d'; 

printf('< a href="https://www.surveymonkey.com/%s" target="_blank"> 
      <img src="http://www.anyfood.gr/net/wp-content/uploads/2014/12/evaluation2.jpg" style="padding:20px;"> 
     </ a>', urlencode($str)); 

檢查此。