###### tags: `cfmlnotes` # PHP und CFML - Zusammenhänge ## Form-Post- und Form-Get-Variablen Bei PHP sind Form-POST-Variablen im globane Array `$_POST[...]` und Form-GET-Variablen im globalen Array `$_GET[...]` gespeichert. Variablen haben in PHP als Prefix immer ein `$`. Wenn man PHP Beispiele hat, kann man das Konzept oft auf CFML übertragen. PHP-Code ist quasi genauso wie CFML-Code, *NUR* dass es nur einen einzigen Tag `<?php ... ?>` gibt, in welchen der **GESAMTE PHP** Code reinkommt - egal ob *set, output, loop* etc. Am Ende der PHP Anweisungen steht immer ein `;`. # Beispiel Das Beispiel zeigt PHP Code und einen möglichen entsprechenden CFML-Befehl. Der Code ist in HTML eingebettet. ```php <html> <head> <!-- lesen der Variable aus dem POST Array --> <?php $va1 = $_POST["va1"]; ?> <!-- bei CFML automatisch, falls Variable gesetzt --> <!-- lesen der Variable aus dem POST Array --> <!-- Handling von nicht gesetzten Variablen --> <?php $va2 = $_POST["va2"]; ?> <!-- setzen einer neuen Variable --> <?php $tmp = "Hallo"; ?> <cfset tmp = "Hallo"> </head> <body> <!-- Ausgabe der Variable zum Client --> <?php print($tmp); ?> Welt!<br> <cfoutput>#tmp#</cfoutput> Welt!<br> <!-- Zählschleiufe --> <!-- PHP --> <ul> <?php for ($i = 0; $i < 10; $i = $i + 1) { ?> <li> <?php print($i); ?> </li> <?php } ?> </ul> <!-- CFML --> <ul> <cfloop index="i" from="0" to="9"> <li> <cfoutput>#i#</cfoutput> </li> </cfloop> </ul> <!-- ... --> </body> </html> ```