Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php script url with special characters

I have this php code in 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've tried several possible tricks using single quotes, etc. but I can't figure it out...Any ideas?

like image 641
marilena6 Avatar asked May 03 '26 15:05

marilena6


2 Answers

Try this, it 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));
?>
like image 157
Prerak Sola Avatar answered May 05 '26 07:05

Prerak Sola


Generally you won't have to use urldecode() when accessing GET parameters. Use it as follow:

$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>';
like image 29
tomloprod Avatar answered May 05 '26 07:05

tomloprod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!