0

I'm having trouble using the echo function in php. I don't fully understand when double quotes, single quotes, and escaping quotes are necessary. I've tried several variations and I can't seem to get it to show up. I know how to echo basic html, but I've not used classes before, I think that might be the dealbreaker here.

Edit: flagged for being a duplicate, I'm new here, not really sure what to do. But it's not duplicate post, the other post uses elements that I'm not familiar with using, this was just straight html. Thank you.

<?php echo  "<div id=\"resume-links\" style='display:flex;float:right;''>
<a class='button button--type-action--size-medium' href='/myaccount' style='margin-right:10px;''>Dashboard →</a>
<a class='button button--type-action--size-medium' href='#popmake-1301'>Get Featured →</a>
</div>
<div id=\"resume-link\" style='clear:both;float:right;padding-top:10px;font-style:italic;'><p><a href='/article-submissions'>Learn More</a></p></div>";?>
7
  • exit out out php ?>html here<?php Commented Apr 5, 2019 at 6:46
  • Possible duplicate of Escape double quotes of HTML attributes output by PHP Commented Apr 5, 2019 at 6:50
  • Basically, since you are echoing a string and you wrap your string with ", you have to escape your " in your echo or php will treat the quote as end of your string. By escaping your ", you tell php that the quote should be printed and is not the closing of the string. Commented Apr 5, 2019 at 6:52
  • Possible duplicate of How can I echo HTML in PHP? Commented Apr 5, 2019 at 6:55
  • Wow! That was quick responses. I have to report that I was a complete bonehead and forgot that I had hidden the divs with CSS. Turns out, I guess I can figure it out. Also exiting out of php makes a whole lot of sense. Sometimes you overthink things I guess. btw, it's not a duplicate post as suspected*. Thank you again! Commented Apr 5, 2019 at 6:59

3 Answers 3

1

You can use

<<<START
    htmlHere
START;

And after margin-left you hav 2 ' but must 1

Sign up to request clarification or add additional context in comments.

Comments

0
  • you can wrap single quotes inside double quotes
echo " <div id='resume-id'>qwerty</div> ";
  • you can wrap double quotes inside single quotes
echo '<div id ="resume-id">qwerty</div>';
  • you can use escape character when your wrapper quotes are same as inner quotes
echo "<div id =\"resume-id\">qwerty</div>";

or

echo '<div id ="resume-id">qwerty\'s</div>';

output : qwerty's

3 Comments

Thank you - this is a helpful guide. Is there any right/wrong way to do it? Is there a suggested standard or is either way deemed acceptable?
it's all up to your preference, you can use any way
wrapping with double quotes is more standard way
0

Use Heredoc syntax.

Example :

$str = <<<EOD
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>

EOD;

Documentation

1 Comment

Thank you for the suggestion.

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.