PHP script url with special characters
I have this PHP code on a Wordpress page
$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>'
);
but the link doesn't work, I tried several possible tricks using single quotes etc. but i cant figure it out ... Any ideas?
+3
source to share
4 answers
Typically you don't need to use urldecode()
when accessing parameters GET
. Use it like this:
$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>';
+2
source to share
$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>
');
** remove * when running anchor tag and image tag **
+1
source to share
Try it, this worked for me:
<?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
source to share