Displaying Html Code within a PHP statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Displaying Html Code within a PHP statement

Post 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
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Displaying Html Code within a PHP statement

Post by watson516 »

I don't quite understand what you're doing but if you echo html, it will get read as html.
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying Html Code within a PHP statement

Post 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.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Displaying Html Code within a PHP statement

Post by watson516 »

Is that information stored in a database? Does the entry go through a function that prevents html from being displayed as html?
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying Html Code within a PHP statement

Post 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.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Displaying Html Code within a PHP statement

Post 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.
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying Html Code within a PHP statement

Post 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;?>
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Displaying Html Code within a PHP statement

Post 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);
 
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying Html Code within a PHP statement

Post 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.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Displaying Html Code within a PHP statement

Post by Ziq »

Code: Select all

<td class="data"><?php echo (nl2br(html_entity_decode($_data['value']))) ?></td>
 
This should work fine.
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying Html Code within a PHP statement

Post by Danielc1234 »

Ziq that WORKED!!!! Thanks so much. I would have never have figured that one out.
Post Reply