Solved

Echo statement rendering html code in output

Posted on 2014-10-06
18
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

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:Cornelia Yoder
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 110

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 58

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 110

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 58

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 110

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
 
LVL 58

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 110

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 110

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 110

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

632 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