NYCPHP Meetup

NYPHP.org

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

Brian Dailey support at dailytechnology.net
Mon Jul 23 13:04:21 EDT 2007


Just remember there are some "gotchas" when using foreach with 
references. If you do this, remember to unset the variable after the 
loop so you don't accidentally overwrite anything.

Cliff Hirsch wrote:
> On 7/23/07 8:47 AM, "Tim B" <timb.php at gmail.com> wrote:
> 
>> Here's the code:
>> # Escape for output into html
>> foreach ($event as $v1)
>> {
>>     foreach ($v1 as $v2)
>>     {
>>        $v2 = htmlentities($v2, ENT_QUOTES, 'UTF-8');
>>        echo "{$v2}<br>";
> 
> V1 and V2 need to be references. See online php manual
> 
> foreach ($event as &$v1)
>> {
>>     foreach ($v1 as &$v2)
> 
> 
> 
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 

-- 

Thanks!
- Brian Dailey
Software Developer
New York, NY
www.dailytechnology.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: support.vcf
Type: text/x-vcard
Size: 264 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070723/e5bfdfdf/attachment.vcf>


More information about the talk mailing list