php - Echo statement rendering html code in output

160

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 href="javascript:void(0)" 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" 
461

Answer

Solution:

Use this instead for your<a/> tag:

<a href="javascript:void(0)" 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 href="javascript:void(0)" title="<?=$titleText;?>">Help</a> 
252

Answer

Solution:

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

People are also looking for solutions to the problem: Quickest way to find the max frequency element in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.