<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Quinterox &#187; script tag</title>
	<atom:link href="http://www.quinterox.com/content/tag/script-tag/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.quinterox.com/content</link>
	<description>Cesar Quinteros</description>
	<lastBuildDate>Sun, 20 Jun 2010 04:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP &#8211; Where to place your code</title>
		<link>http://www.quinterox.com/content/code/php-where-to-place-your-code/</link>
		<comments>http://www.quinterox.com/content/code/php-where-to-place-your-code/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 06:11:15 +0000</pubDate>
		<dc:creator>Cesar Quinteros</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[script tag]]></category>

		<guid isPermaLink="false">http://www.quinterox.com/content/?p=394</guid>
		<description><![CDATA[There are a few places where to place your PHP code on your dynamic web page. This all depends on your needs and preference. Of course there is a slight difference to whether you put it on a script tag, before any HTML, within your HTML, or at the bottom of the page. Here I will explain what I have found some of the differences to be.]]></description>
			<content:encoded><![CDATA[<p>There are a few places where to place your PHP code on your dynamic web page. This all depends on your needs and preference. Of course there is a slight difference to whether you put it on a script tag, before any HTML, within your HTML, or at the bottom of the page. Here I will explain what I have found some of the differences to be.</p>
<h3>Before HTML</h3>
<p>A few of the reasons you would want to place your code before the HTML are because you want to redirect the user to another page on your website, or getting data out of a database and placing it on your page as content.</p>
<pre><span style="color: #ff6600;"><span>&lt;?<span>php</span> $<span>pageTitle</span> = "Cesar's page"; ?&gt;</span></span>
<span>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.<span>dtd</span>"&gt;</span>
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
<span>&lt;meta http-equiv="Content-Type" content="text/html; <span>charset</span>=<span>utf</span>-8" /&gt;</span>
&lt;title&gt;<span style="color: #ff6600;"><strong><span>&lt;?<span>php</span> echo $<span>pageTitle</span>; ?&gt;</span></strong></span>&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt; ...</pre>
<p><br class="break" /></p>
<h3>In the script tag</h3>
<p>Yes! Just like Javascript you can place your PHP code within a script tag, but also like Javascript gets executed after your page loads. Though I have not seen many people using this method I think it really helps you keep your code clean and organized. It is similar to the .NET code placement.</p>
<pre><span>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.<span>dtd</span>"&gt;</span>
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
<span>&lt;meta http-equiv="Content-Type" content="text/html; <span>charset</span>=<span>utf</span>-8" /&gt;</span>
&lt;title&gt;My Web Page&lt;/title&gt;
<span style="color: #ff6600;"><strong><span>&lt;script language="<span>php</span>"&gt;</span>
$pageContent = "Cesar's page content.";
&lt;/script&gt;</strong>
</span>&lt;/head&gt;
&lt;body&gt;
<span>&lt;?<span>php</span> echo $<span>pageContent</span>; ?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><br class="break" /></p>
<h3>Within HTML</h3>
<p>Mixing HTML and PHP is probably the most common way PHP applications are made. As useful and conventional as this type of coding can be, it can also become confusing. Below is an example of how that looks.</p>
<pre><span>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.<span>dtd</span>"&gt;</span>
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
<span>&lt;meta http-equiv="Content-Type" content="text/html; <span>charset</span>=<span>utf</span>-8" /&gt;</span>
&lt;title&gt;My Web Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<span style="color: #ff6600;"><strong><span>&lt;?<span>php</span></span>
<span>$<span>HeadDiv</span> = "&lt;div&gt;&lt;h1&gt;Welcome to my website!&lt;/h1&gt;&lt;/div&gt;";</span>
$BodyDiv = "&lt;div&gt;&lt;p&gt;Are you ready to hire me?! Click on my port...&lt;/p&gt;&lt;/div&gt;";
<span>$<span>FooterDiv</span> = "&lt;div&gt;copyright ...&lt;/div&gt;";</span>
?&gt;
<span>&lt;?<span>php</span></span>
<span>echo $<span>HeadDiv</span>;</span>
<span>echo $<span>BodyDiv</span>;</span>
<span>echo $<span>FooterDiv</span>;</span>
?&gt;</strong>
</span>&lt;/body&gt;
&lt;/html&gt;</pre>
<p><br class="break" /></p>
<h3>After HTML</h3>
<p>This might be an unorthodox way of code execution but nonetheless it is a possibility and depending on your application needs, it might be a useful one. Your code will execute after the HTML so anything that would be rendered above your HTML will render below it (afterwards) now. Here is how that looks. Please comment if you have an idea of how it would be useful.</p>
<pre><span>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.<span>dtd</span>"&gt;</span>
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
<span>&lt;meta http-equiv="Content-Type" content="text/html; <span>charset</span>=<span>utf</span>-8" /&gt;</span>
&lt;title&gt;My WebApp&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<span>&lt;form action="/code/untitled.<span>php</span>" method="post"&gt;</span>
&lt;input type="text" name="txtMessage" /&gt;
&lt;input type="submit" value="submit" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
<strong><span style="color: #ff6600;"><span>&lt;?<span>php</span> echo $_POST['txtMessage'];?&gt;</span></span></strong></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quinterox.com/content/code/php-where-to-place-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The script tag</title>
		<link>http://www.quinterox.com/content/code/the-script-tag/</link>
		<comments>http://www.quinterox.com/content/code/the-script-tag/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 00:09:13 +0000</pubDate>
		<dc:creator>Cesar Quinteros</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[script tag]]></category>

		<guid isPermaLink="false">http://quinterox.com/code/?p=12</guid>
		<description><![CDATA[Shows simply how to add JavaScript, or attach JavaScript files to your web page.]]></description>
			<content:encoded><![CDATA[<p>There are two ways of adding JavaScript to a web page.</p>
<p>The first one allows you to add scripts directly to your page.</p>
<pre>&lt;script type="text/javascript"&gt;
:::scripts:::
&lt;/script&gt;</pre>
<p>The other way is attaching a JavaScript file to your web page like so.</p>
<pre>&lt;script type="text/javascript" src="my-javascript-file.js"&gt;&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quinterox.com/content/code/the-script-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
