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>";?>
joy
  • 101
  • 9
  • exit out out php `?>html here – Lawrence Cherone Apr 05 '19 at 06:46
  • Possible duplicate of [Escape double quotes of HTML attributes output by PHP](https://stackoverflow.com/questions/1097135/escape-double-quotes-of-html-attributes-output-by-php) – josephting Apr 05 '19 at 06: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. – josephting Apr 05 '19 at 06:52
  • Possible duplicate of [How can I echo HTML in PHP?](https://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php) – R P Apr 05 '19 at 06: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! – joy Apr 05 '19 at 06:59
  • Glad you were able to get to the bottom of it @joy :) . (Note you can actually leave an answer to your own question if you have solved it yourself). To help in these situations in future I would suggest investigating using the inspector and dev tools in the browser so you can see and work with the actual HTML that the browser has received. E.g. https://developers.google.com/web/tools/chrome-devtools/ – ChrisM Apr 05 '19 at 07:10
  • You might also want to take a look at the [Heredoc syntax](https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) – brombeer Apr 05 '19 at 07:16

3 Answers3

1

You can use

<<<START
    htmlHere
START;

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

Veyis Aliyev
  • 313
  • 2
  • 11
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
Siraj Ahmad
  • 466
  • 4
  • 11
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

Golden_flash
  • 492
  • 1
  • 6
  • 14