0

I know this is something really simple but it is not working for me....

I am using the following to display a variable within html.

<?php if (!empty($data['title_text'])) {
    echo '<h1 class="site-title animated fadeInDown">' .$data['title_text']. '</h1>'; 
}

It is displaying but the varibale is not within the html element. It is displaying like so

TEST DATA
<h1 class="site-title animated fadeInDown"></h1>
2
  • 2
    Please provide the output of var_dump($data) Commented Jan 9, 2014 at 16:31
  • What encode do you use? Commented Jan 9, 2014 at 16:38

2 Answers 2

1

Your variable might contain characters that invalidate / mess with the html. You should always make sure that cannot happen:

echo '<h1 class="site-title animated fadeInDown">' . htmlspecialchars($data['title_text'], ENT_QUOTES, 'UTF-8') . '</h1>';

(assuming you are using utf-8)

Sign up to request clarification or add additional context in comments.

5 Comments

If you're using UTF-8 then htmlentities($data['title_text'], ENT_QUOTES, 'UTF-8') might be a better use, right?
@CBergau When not inside an html tag / property value I don't see how single quotes could do any harm and utf-8 is the default from php 5.4 on. Anyway, it certainly won't hurt :-) Edited!
I wasn't mentioning htmlentites because of the quotes. Just wanted to point on the encoding :)
Actually i made i mistake here. The default value is already UTF-8 see de2.php.net/manual/en/function.htmlspecialchars.php :-)
@CBergau No, see my previous comment, only since php 5.4, check the manual on the encoding parameter.
0

Try this add this part of code on your page:

define('CHARSET', 'ISO-8859-1');
define('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML);

Comments

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.