3

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?

2
  • or try this htmlspecialchars($str); Commented Dec 26, 2014 at 10:09
  • @marilena6 I think you forgot mark one answer as the correct answer. Commented Dec 30, 2014 at 7:45

4 Answers 4

1

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));
?>
Sign up to request clarification or add additional context in comments.

Comments

1

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>';

Comments

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>
');

**remove the * at the starting of Anchor tag and image tag **

Comments

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));

check this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.