Need help with PHP and $node arrays
blogjunkie - January 11, 2008 - 00:37
I want to loop through $node->attachments and print out selected data into an unordered list. Presently I'm using this really bad solution:
<ul>
<?php
for ($row = 0; $row < 3; $row++) {
echo "<li>".$node->attachments[$row]['title']."</li>";
}
?>
</ul>
Please someone show me a better way. Thanks.

Try this...
<ul><?php foreach ($node->attachments as $atm) : ?>
<li><?php print($atm['title']); ?></li>
<?php endforeach; ?>
</ul>
yay!
it worked, thanks!
You cannot just print user
You cannot just print user input verbatim as this may easily lead to cross site scripting vulnerabilities.
See http://drupal.org/writing-secure-code and http://drupal.org/node/28984
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
thanks for the warning
thanks for the warning heine, but as you can see from my question I'm a PHP noob. i wouldn't know how to code securely if my life depended on it.
in any case, i figured out how to do it by overiding some theme functions. thanks
But?
Why the but? I'm not accusing you of anything.
I assumed you
The pages on http://drupal.org/writing-secure-code were written* as part of a security education effort with the intent to inform all developers about security issues and — as a result — decrease the amount of vulnerabilities in both Drupal core and contributed modules.
We are very interested to receive feedback on these pages. Are they clear, too difficult? What can be done to make the info easier to digest (without dumbing down)?
Another part of the education effort is to increase awareness by posting "Remember to do x,y, see the security guide, [link here]"-comments on forum posts containing snippets and informing the wider Drupal community of issues via Planet Drupal.
That said; Enjoy learning PHP & webdevelopment :)
Tip: http://www.php.net/manual/en/langref.php is rather good.
* some pages are still in progress.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.