Return to Snippet

Revision: 2662
at March 20, 2007 19:24 by juno


Updated Code
<?php
foreach ($contacts as $contact_object) {
  $contact_array = (array) $contact_object;
  foreach ($contact_array as $key=>$value) $$key = h($value);
  echo <<<END_ROW
    <tr>
      <td>$id</td>
      <td>$first_name</td>
      <td>$last_name</td>
      <td>$phone</td>
      <td>
        <a href="?action=edit&amp;id=$id">edit</a>
        <a href="?action=delete&amp;id=$id">delete</a>
      </td>
    </tr>
END_ROW;
}

Revision: 2661
at March 20, 2007 19:22 by juno


Initial Code
<?php foreach ($contacts as $contact_object) 
{ $contact_array = (array) $contact_object; 
foreach ($contact_array as $key=>$value) 
$$key = h($value); echo <<<END_ROW <tr> <td>$id</td> <td>$first_name</td> <td>$last_name</td> <td>$phone</td> <td> <a href="?action=edit&id=$id">edit</a> <a href="?action=delete&id=$id">delete</a> </td> </tr> END_ROW; }

Initial URL
http://pdxphp.org/articles/escaping-injected-data

Initial Description
The above example uses PHP's heredoc syntax. With it, we can completely eliminate PHP tags from the insides of HTML tags.

Initial Title
user PHP's heredoc syntax

Initial Tags
php, html

Initial Language
PHP