0

This is such a basic question that I feel embarrassed asking it. Whenever I echo html tags, instead of rendering the tag, it just displays in the echo output. I have tried single and double quotes, but still no luck. What am I doing wrong here? Thanks

<a style="margin-left: 12px;" href="javascript:void(0)" class="tooltip" title="<?php echo "Please select your boxes from the list. You can select a max of 20 boxes per submission.<br />You can select multiple boxes by holding the left ctrl on your keyboard and making your selection"; ?>">Help</a> 

ff rendered output:

title="Please select your boxes from the list. You can select a max of 20 boxes per submission.<br />You can select multiple boxes by holding the left ctrl on your keyboard and making your selection" 
6
  • 1
    Do you mean that it includes <?php in the source code? It sounds like you're not going through your PHP interpreter. If PHP is actually installed you've most likely named your page .html instead of .php. Could you post an example on eval.in or codepad.org? Commented Oct 6, 2014 at 11:42
  • What are you trying to accomplish? Echoing HTML while incorporating PHP? Commented Oct 6, 2014 at 11:43
  • Could you please paste the output so that we can see what actually is happening and if it is the expected result or not. The things that you have posted is the output or your code ?? Commented Oct 6, 2014 at 11:44
  • This is what is being rendered in ff view source. title="Please select your boxes from the list. You can select a max of 20 boxes per submission.<br />You can select multiple boxes by holding the left ctrl on your keyboard and making your selection" You can see that the <br /> is being output with the echo. Commented Oct 6, 2014 at 11:50
  • @adam I am trying to use html tags in php echo. thanks Commented Oct 6, 2014 at 11:51

2 Answers 2

1

Use this instead for your <a/> tag:

<a style="margin-left: 12px;" href="javascript:void(0)" class="tooltip" title="<?php echo 'Please select your boxes from the list. You can select a max of 20 boxes per submission.<br />You can select multiple boxes by holding the left ctrl on your keyboard and making your selection';?>">Help</a> 

Or alternatively:

<?php 
$titleText =  'Please select your boxes from the list. You can select a max of 20 boxes per submission.<br />You can select multiple boxes by holding the left ctrl on your keyboard and making your selection';
?>

<a style="margin-left: 12px;" href="javascript:void(0)" class="tooltip" title="<?=$titleText;?>">Help</a> 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks adam, but still outputting the same result.
Then it is a problem with your setup, not your code. Is the code contained in a file with .php extension?
It is definately a .php file. All php code runs in the file except this code. I think Ole may have supplied the answer.Thanks
1

HTML code can not be put inside a title tag as browser will not render titles as anything else than a pure text string.

4 Comments

Thanks Ole. However, all I am trying to do, is to use a <br /> to seperate the lines. thanks
Oh, okay. I misunderstood you then. You cannot render html code in the title tag.
Is that even if using php within the title? because I am sure I have used $var before in title with html formatting. Thanks
PHP is a script that is run server side, before HTML is sent to the visitors browser, where the HMTL code then is rendered. So you can use php wherever you like on your website. That being within html tags or not. The only point is, that browser will not render html code within a title tag. All PHP does here is input some value to the tag, before the browser have recieved it. For all the visitors browser knows, this could be a static html file.

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.