1

I'm stuck trying to echo my product descriptions correctly for my eCommerce store.

Is it possible to write formatted HTML (i.e. with elements and tags... to youtube links, etc) as text in a MySQL description field and then echo it with PHP correctly formatted?

At the moment I am using...

<?php

  echo "<p>".Helper::encodeHTML($product['description'])."</p>";

?>

...but as I say it doesn't output as formatted.

Thanks for the help! :)


Edit; Fixed for the moment ('less anything changes) with...

echo html_entity_decode($var['string']);

i.e.

echo html_entity_decode($product['description2']);

https://www.php.net/manual/en/function.html-entity-decode.php

9
  • 1
    what framework or library is this Helper::encodeHTML from? Commented Jul 27, 2015 at 23:00
  • if you trying to echo $product['description'] it is not good? without Helper::encodeHTML Commented Jul 27, 2015 at 23:05
  • It seems like the 'Helper::encodeHTML' is removing the html tags. As you can just save it with html tags and echo it. Commented Jul 27, 2015 at 23:08
  • I'm not sure. Sorry, I'm such a newbie. I just checked out another post... stackoverflow.com/questions/8381651/… ...can I do something like that, but echo $product['description]? I'm using PHPMyAdmin and the description field is set to text. Thanks! :) Yes, the tags are posted but not formatted correctly as HTML markup. Commented Jul 27, 2015 at 23:08
  • Actually it might be working ok. I think I need to add a second field called description2 and add HTML there instead, as I'm echo'ing this in two places... one using Helper::shortenString to shorten the description, and then parse the full description on the product page. Commented Jul 27, 2015 at 23:13

1 Answer 1

0

How about removing the p tag and echo it as is?

    <?php
    echo Helper::encodeHTML($product['description']);
    ?>

or echo it with htmlentities() like this:

    <?php
      echo htmlentities($product['description']);
    ?>

or echo it directly like this:

    <?php
      echo $product['description'];
    ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Those don't seem to work, it just outputs the tags and doesn't format... i.e. <h1>Contents: -</h1> <iframe width="420" height="315" src="youtube.com/embed/XGSy3_Czz8k?autoplay=1"> </iframe>

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.