PHP loop hanging/interspersed/threaded through HTML
Posted
by sandyv
on Stack Overflow
See other posts from Stack Overflow
or by sandyv
Published on 2010-03-12T04:32:58Z
Indexed on
2010/03/12
4:37 UTC
Read the original article
Hit count: 212
I can't figure out how to say what I'm talking about which is a big part of why I'm stuck. In PHP I often see code like this
html
<?php
language construct that uses brackets {
some code;
?>
more html
<?php
some more code;
}
?>
rest of html
Is there any name for this? Having seen this lead me to try it out so here is a concrete example whose behavior doesn't make sense to me
<div id="content">
<ul id="nav">
<?php
$path = 'content';
$dir = dir($path);
while(false !== ($file = $dir->read())) {
if(preg_match('/.+\.txt/i', $file)) {
echo "<li>$file</li>";
?>
</ul>
<?php
echo file_get_contents($path . '/' . $file);
}
}
?>
</div>
Which outputs roughly <div><ul><li></li></ul><li></li>...</div>
instead of <div><ul><li></li>...</ul></div>
which is what I thought would happen and what I want to happen.
© Stack Overflow or respective owner