0

I am using php and conditional code to give a dynamic url to a photo. The result should read as http://example.com/biophotos/1.jpg. But instead I am getting http://example.com/%22http://example.com/biophotos/1.jpg%22

How can I force it to just give the one url and without the %22 space on the end?

if ($emresult[0]['photo'] = "y") {
echo '<img class=\"alignright\" src=\"http://example.com/biophotos/' .
$theID . '.jpg" width=\"150\" height=\"150\">';
}
else {
echo 'There is no author photo.';
}
3
  • 1
    You shouldn't escape double quotes when using single quotes for your echo. Commented Jul 4, 2015 at 5:21
  • That did the trick removing the escaping. Thanks! However, it doesn't give me the else "There is no photo" if the condition is not met. Do you see an obvious reason why? $theID is variable capturing the user's ID from a previous page. Commented Jul 4, 2015 at 5:26
  • nevermind. I needed == instead of = in the if Commented Jul 4, 2015 at 5:28

2 Answers 2

1

There is no reason in escaping double quotes when your using single quotes.

echo '<img class="alignright" src="http://example.com/biophotos/' . $theID . '.jpg" width="150" height="150" />';
Sign up to request clarification or add additional context in comments.

Comments

0

As much as I agree with @slik, you also might want to look into %22 (double quotes) added to url out of nowhere

Check if magic quotes is on in your php.ini file. You can look into html_entity_encode() to encode the %22 as a slash.

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.