PHP vs ColdFusion/Inserting Variables

From Wikibooks, open books for an open world
< PHP vs ColdFusion
Jump to: navigation, search

Inserting Variables[edit]

Both languages allow you to insert variables at any point. This is very useful if you have many lines of HTML, but only need to insert something simple. We will use the variable we created above.

PHP:

Message holds: <?=$message; ?>

(Note: This will not work in php if short open tags are disabled. This was enabled by default as of php 4.0.0)

ColdFusion:

Message holds: <cfoutput>#message#</cfoutput>

(Note: It is considered poor form in CFML to place <cfoutput> tags at the beginning and end of a page, as the parser must evaluate every word for variables).

Both examples will print: Message holds: Hello World!