PHP code working beyond PHP tags (<?php ... ?>) -
i've been reading book on zend framework , there's html/php code section can't figure out. it's contained in views part of mvc methodology:
<select name="genre"> <?php foreach ($this->genres $genre) { ?> <option value="<?php echo $genre ?>"><?php echo $genre ?></option> <?php } ?> </select> the genre ($this->genres) refers array('rock', 'r&b', 'country', 'rap', 'gospel', 'rock n roll', 'techno').
the code runs perfectly, producing drop-down select menu, don't understand how second line legal, let alone work. how php code work beyond enclosing tags?
php unusual (templated) language in context. parser considers between ?> , <?php being weird kind of echo. ignored part of program code, although parser run (it outputs , skips part of program code).
from php manual:
everything outside of pair of opening , closing tags ignored php parser allows php files have mixed content. allows php embedded in html documents, example create templates.
(...)
works expected, because when php interpreter hits ?> closing tags, starts outputting whatever finds (except following newline - see instruction separation) until hits opening tag unless in middle of conditional statement in case interpreter determine outcome of conditional before making decision of skip over.
this allows php used numerous of things. can't create dynamic html files it, can example create xml (although it's bit tricky xml header right), text files, css files, etc., long php interpreter ran file, execute between <?php , ?> program code , rest outputted as-is.
Comments
Post a Comment