Solved

Echo statement rendering html code in output

Posted on 2014-10-06
18
171 Views
Last Modified: 2014-10-07
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> 

Open in new window


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" 

Open in new window

0
Comment
Question by:peter-cooper
  • 6
  • 6
  • 4
  • +2
18 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 250 total points
ID: 40363461
Are you trying to display newline inside the title tag ?
Try:

title="<?php echo "Please select your boxes from the list. You can select a max of 20 boxes per submission.&#013;You can select multiple boxes by holding the left ctrl on your keyboard and making your selection"; ?>"
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40363480
It is not PHP that is the problem - that is working it is how to put a line break in a title try replacing your <br/> with \n - string must be in double quotes
<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.\nYou can select multiple boxes by holding the left ctrl on your keyboard and making your selection"; ?>">Help</a> 

Open in new window

0
 
LVL 27

Expert Comment

by:yodercm
ID: 40363550
Producing HTML output is the normal use of echo in this way.

If you want to actually show the HTML tags, you need to surround it with

htmlspecialchars()

which is a php function that changes special characters to their ascii codes.

$x = htmlspecialchars("Here is real HTML <br>");
echo $x;


http://us2.php.net/manual/en/function.htmlspecialchars.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40363558
The "deep background" on PHP's use of quotes:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

The code snippet, copied and pasted from the original post is here:
http://iconoun.com/demo/petercooper.php

It does not do anything odd, so I would surmise that there is something else afoot.  Can you please create the SSCCE that enables us to reproduce the problem?
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40363647
No SSCCE needed he is outputing HTML tags into a title string which is agent dependent on how it is rendered - however the default is to render it as text - not as html -  therefore the <br/> will be treated as text and not interpreted as a line break.

Solution is to insert a line break directly into the text.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40363814
@julianH: I understood that ff rendered output: meant "Firefox rendered output:" and so I copied the code snippet, installed it on my server and visited it in Firefox.  The URL on my server is here:
http://iconoun.com/demo/petercooper.php

A screenshot of the rendered document:HelpSince this did not look like the "ff rendered output" in the question, there is some disconnect in our understandings of the issue.  Ergo, I asked for a test case that was able to demonstrate the issue.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40364019
@Ray - looks identical to me - unfortunately your screen shot does not show what happens if you hover over the link - if you did you would see the following
 ss.jpgAs I understand it the problem is the <br/> appearing in the title popup - which was demonstrated by the author in his second code snippet of his original post.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40364061
Ahh, I see now.  If that's the real issue, the correct answer is right at the top:
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28531936.html#a40363461

But now that I understand the question, this has nothing to do with PHP and echo.  In fact, PHP is not needed to render the title attribute.  Just put in the newline character directly.  Easy!

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

Open in new window

0
 

Author Comment

by:peter-cooper
ID: 40364453
Thanks for comments guys. However, neither the \n method or the &#013; method work. They do not echo, but they do not put the text on a new line, like a <br  /> tag would. Thanks
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 40364552
What are the results you are expecting?
Maybe tell us what you want and not what you are getting.
Notwithstanding the comments above about the superfluous nature of the PHP echo for achieving the output below - the code is provided for illustrative purposes as we do not know how you intend to use it.
<a href="#" title="<?php echo "Please select your boxes from the list. You can select a max of 20 boxes per submission.\nYou can select multiple boxes by holding the left ctrl on your keyboard and making your selection";?>">Link</a>

Open in new window

Screen shot of \n below - how is this different from what you are wanting?

t725.jpg
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40364976
Please recheck your code carefully, then post the exact URL of your test case that demonstrates the issue.  I can see no reason why our demonstration scripts and test cases should produce different output from your demonstration script.  This is why we ask for the SSCCE -- it disambiguates so many things that can be lost in explanations.
0
 

Author Comment

by:peter-cooper
ID: 40365565
I have included screenshot where it is not putting the text on a new line. I think perhaps it could have something to do with a jquery plugin I am using, tooltipster. Should have thought of that in the first place. If I remove the class then it displays correctly as a title with cr and lf etc. But not with tooltipster. I shall report back. Thanks
0
 

Author Comment

by:peter-cooper
ID: 40365568
Title error pic
0
 

Author Comment

by:peter-cooper
ID: 40365588
Should have checked this first. Tooltipster has a method, contentAsHTML: true where you can include html in title tag. If it is ok, I shall split the points with Julian and Lukasz. Thanks
0
 

Author Closing Comment

by:peter-cooper
ID: 40365589
Thanks very much for help.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40365712
E-E has a jQuery Zone.  It would probably have made for a quicker solution if you had told us you were using a jQuery plug-in, and what the plug-in was called and how you were using it.  It's this sort of thing that we seek to understand when we ask you for the SSCCE because while we are experts, we are not mind readers and we need your fullest explanation and exposition to discern the important details in your question.
0
 

Author Comment

by:peter-cooper
ID: 40365721
Thanks Ray for your comment. You are absolutely right in what you say. I should have realized that and had I done so, would not have needed to post at all :-). Thanks for input.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40365845
Yeah, I get it.  As Kettering said, "A problem well stated is a problem half solved!"
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now