NYCPHP Meetup

NYPHP.org

[nycphp-talk] Escaping output in array isn't working

Tim B timb.php at gmail.com
Mon Jul 23 08:47:37 EDT 2007


Hello

I surely this is easy & I'm just overlooking something...

Basically, I'm wanting to copy $event into $html, but have all the 
values within the nested array escaped with htmlentities().

The problem must be this line:
$v2 = htmlentities($v2, ENT_QUOTES, 'UTF-8');

...but I have no idea how to fix it!

Is anyone able to point me in the right direction?

Thanks
Tim


Here's the code:

<?php

# Sample array data
$event[0]['title'] = '"Tea & Biscuts" Evening';
$event[0]['desc']  = 'At my house.';
$event[1]['title'] = '"Cheese & Wine" Lunch';
$event[1]['desc']  = 'At yours!';

# Escape for output into html
foreach ($event as $v1)
{
    foreach ($v1 as $v2)
    {
       $v2 = htmlentities($v2, ENT_QUOTES, 'UTF-8');
       echo "{$v2}<br>";
    }
}
$html = $event;

echo '<h2>html</h2><pre>';
print_r($html);
echo '</pre>';
exit;

?>





More information about the talk mailing list