Page 1 of 1
Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 4:54 pm
by Danielc1234
Hi all. I'm not sure if I am doing this right, but I some html code that I am pulling from a database via php statement.
<td class="data"><?php echo (nl2br($_data['value'])) ?></td>
The problem is it is displaying the html code not the execution of the html code, ie links, etc.
Is the the proper way to do this?
Thanks
Daniel
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 4:58 pm
by watson516
I don't quite understand what you're doing but if you echo html, it will get read as html.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 5:07 pm
by Danielc1234
Thats what I thought but for some reason it is not. Take a look on this page at the assembly instructions. It is displaying the html code.
http://www.poly- wood -furniture . (take out spaces) com/polywood-chairs/polywood-adirondack-chairs/polywood-adirondack-chair.html
And I am using the echo command I posted first.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 5:11 pm
by watson516
Is that information stored in a database? Does the entry go through a function that prevents html from being displayed as html?
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 5:36 pm
by Danielc1234
Is that information stored in a database? Does the entry go through a function that prevents html from being displayed as html?
Yes it is stored in a database. And I'm not sure if it goes through a function or not. How would I be able to tell? This is a shopping cart software that is fully open source.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 5:43 pm
by Ziq
Maybe this can help you:
get_html_translation_table()
But in any case better if you will understand why you have this result.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 5:59 pm
by Danielc1234
Below is the .phtml file that is generating the output. The example you showed me seems like it is doing the reverse of what I am trying to do. Unless I'm not understanding it very well. I do not know too much php.
Code: Select all
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="collateral-box attribute-specs">
<table cellspacing="0" class="data-table" id="product-attribute-specs-table">
<?php foreach ($_additional as $_data): ?>
<tr>
[color=#FF0000] <td class="label"><?php echo (nl2br($_data['label'])) ?></td>
<td class="data"><?php echo (nl2br($_data['value'])) ?></td>[/color] - generating output
</tr>
<?php endforeach; ?>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
</div>
<?php endif;?>
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 6:04 pm
by Ziq
Sorry. Russian version of this article has this example:
Code: Select all
<?php
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$original = strtr($encoded, $trans);
In your example you need to replace last line to
Code: Select all
$original = strtr($_data['label'], $trans);
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 6:07 pm
by Danielc1234
Could you do me a favor?
Using these parameters, could you create what the new line would look like using my variables?
<td class="data"><?php echo (nl2br($_data['value'])) ?></td>
Thanks for your time.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 6:08 pm
by Ziq
Code: Select all
<td class="data"><?php echo (nl2br(html_entity_decode($_data['value']))) ?></td>
This should work fine.
Re: Displaying Html Code within a PHP statement
Posted: Wed Feb 04, 2009 6:18 pm
by Danielc1234
Ziq that WORKED!!!! Thanks so much. I would have never have figured that one out.