0

I have a seemingly easy task, but I'm struggling a bit. I know that I need to escape the quotes, but I cant seem to get the combination correct.

$referringURL = $_SERVER['HTTP_REFERER'];
echo "<a href = ".$referringURL./MyAccount/SearchUser.aspx" class = "back">Return to Search Users page</a>";
1
  • just escape any " in the html wherey ou DON'T want to leave "string mode" in php, echo "<a href=\"foo\">hi mom</a>"; Commented Sep 1, 2016 at 15:22

4 Answers 4

1

It is worth from time to time mix quotes

echo '<a href = "' . $referringURL . '/MyAccount/SearchUser.aspx" class = "back">Return to Search Users page</a>';
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thanks for the quick reply.
1

Forget escaping, use Heredoc

echo <<<HTML
<a href = "$referringURL/MyAccount/SearchUser.aspx" class = "back">
Return to Search Users page
</a>
HTML;

The actual problem in your code is a missing " before ./MyAccount and 3 unescaped " after that

Comments

0

Have fun

$referringURL = $_SERVER['HTTP_REFERER'];
echo "<a href = '".$referringURL."/MyAccount/SearchUser.aspx' class='back'>Return to Search Users page</a>";

Comments

0

To avoid quotation problems it is possible to separate the main string and the strings to be inserted by using sprintf : each string to insert is represented in the main string by %s, then you add as many strings as %s you have:

<?php
$referringURL = $_SERVER['HTTP_REFERER'];
$s = sprintf( "<a href = '%s' class = '%s'>Return to Search Users page</a>",
              $referringURL . "/MyAccount/SearchUser.aspx",
              "back" );
echo $s;
?>

This method is less confusing when concatenating multiple strings.

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.