-2

I am trying to add HTML to my php return response which is within an if/else statement, Basically it looks something like so(I have omitted the top portion) but the if part goes like so...

  <?php
      if ($c > 1200) {
     Echo "The blab bla bla, bla blah blah blah" .$c;
  }
  ?>

I want to have HTML in the response but I can't find an answer here which would help and relate things for me and my problem. Any help appreciated here, thanks. Oh and I have not figured out how to mark the answer 'answered' but I will do that, thanks.

GreatScott
  • 57
  • 1
  • 10
  • 6
    You need to get in the habit of [accepting answers](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which help you to solve your issues. You'll earn points and others will be encouraged to help you. – Jay Blanchard Mar 29 '16 at 16:13
  • 2
    You can put html in quotes: `echo '

    simple

    ';`
    – Jay Blanchard Mar 29 '16 at 16:14
  • Yes I understand the underlying premise. Which is why I now intend to respond to answers. Of which I would like to add have all been appreciated and helped me in the past. Good on you! – GreatScott Mar 29 '16 at 16:15
  • What exactly is your issue? Certainly the contents of `$c` will get echoed here. – arkascha Mar 29 '16 at 16:17
  • 1
    Possible duplicate of [Is there any way to return HTML in a PHP function? (without building the return value as a string)](http://stackoverflow.com/questions/528445/is-there-any-way-to-return-html-in-a-php-function-without-building-the-return) – workabyte Mar 29 '16 at 16:17
  • Well, When I place a

    tag before the echo statement and a closing

    tag after the echo statement my ide is throwing an exception. If I place any HTML around the echo which is itself of course within the if block It spits an exception.
    – GreatScott Mar 29 '16 at 16:22
  • Trying to make sense of that. – GreatScott Mar 29 '16 at 16:22
  • `echo '

    ' . $c . '

    ';` should work fine as long as you're on a web server.
    – Jay Blanchard Mar 29 '16 at 16:24
  • I'll try what you suggest workabyte, thanks. – GreatScott Mar 29 '16 at 16:25
  • Ok thanks Jay Blanchard, will check into that as well. Will work on it and post back in about 1/2 hour, cheers all. – GreatScott Mar 29 '16 at 16:26
  • Figured it out thanks again. Jay Blanchard answer is what I used, although I also appreciate your here doc reference workabyte. Ok, you folks are going to have a laugh, how do I vote the correct answer? – GreatScott Mar 29 '16 at 17:06
  • Excellent. So basically the answer is : use concatenation to add your strings together with your variable. The concatenation operator in php is the . The single quotations are wrapped around each HTML tag like so-'

    ' . 'Thanks again' . '

    ' . '

    ' . $c . '

    ';
    – GreatScott Mar 29 '16 at 17:31

1 Answers1

1

Excellent. So basically the answer is : use concatenation to add your strings together with your variable. The concatenation operator in php is the . The single quotations are wrapped around each HTML tag like

so-

 '<p>' . 'Thanks again' . '</p>' . '<p>' . $c . '</p>';
War10ck
  • 12,387
  • 7
  • 41
  • 54
GreatScott
  • 57
  • 1
  • 10
  • Since the HTML and the string contents are both strings as far as PHP is concerned you only need to concatenate the `$c` like so: `echo '

    Thanks again

    ' . $c . '

    ';` Including the HTML and string contents together will work just the same.
    – War10ck Mar 29 '16 at 17:38