{"id":1270,"date":"2018-01-19T19:22:38","date_gmt":"2018-01-19T19:22:38","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/the-abcs-of-php-part-3-basic-script-building-in-php\/"},"modified":"2018-01-19T19:24:39","modified_gmt":"2018-01-19T19:24:39","slug":"the-abcs-of-php-part-3-basic-script-building-in-php","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/the-abcs-of-php-part-3-basic-script-building-in-php\/","title":{"rendered":"The ABC&#8217;s of PHP Part 3 &#8211; Basic Script Building in PHP"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Peter Shaw<\/div>\n<div class=\"\">on March 26, 2009<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nWelcome to part 3 of my 10 part series on PHP.  In the first<br \/>\ntwo parts I introduced you to the language and to what<br \/>\nsoftware you needed to run it.\n<\/div>\n<div class=\"articlePara\">\nIn this episode we will look at some simple PHP syntax, and<br \/>\nwe&#8217;ll write a couple of small scripts to get our feet wet,<br \/>\nand get a feel for the language.\n<\/div>\n<div class=\"articlePara\">\nWhat does a PHP script look like?\n<\/div>\n<div class=\"articlePara\">\nPHP traditionally is embedded into HTML code within a web<br \/>\npage, as this was its initial intent.  However it&#8217;s becoming<br \/>\nincreasingly more popular for web application authors to<br \/>\nwrite and generate the HTML using PHP from a page that is<br \/>\nmade entirely of PHP code.\n<\/div>\n<div class=\"articlePara\">\nThe following two examples of the world renowned hello world<br \/>\nprogram should help to show the difference:\n<\/div>\n<div class=\"articleHeader\">\nEmbedding in HTML\n<\/div>\n<pre>\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;&lt;?php print \"My First Script\"; ?&gt;&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;?php\n        \n        print \"&lt;h1&gt;Hello World&lt;\/h1&gt;\";\n\n      ?&gt;\n    &lt;\/body&gt;\n  &lt;\/html&gt;\n<\/pre>\n<div class=\"articleHeader\">\nFull PHP\n<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p>\u00a0\u00a0<span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0$content\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;html&gt;nt&lt;head&gt;ntt&lt;title&gt;\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$content\u00a0<\/span><span style=\"color: #007700\">.=\u00a0<\/span><span style=\"color: #DD0000\">\"My\u00a0First\u00a0Script\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$content\u00a0<\/span><span style=\"color: #007700\">.=\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;\/title&gt;nt&lt;\/head&gt;n\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$content\u00a0<\/span><span style=\"color: #007700\">.=\u00a0<\/span><span style=\"color: #DD0000\">\"t&lt;body&gt;nt&lt;h1&gt;\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$content\u00a0<\/span><span style=\"color: #007700\">.=\u00a0<\/span><span style=\"color: #DD0000\">\"Hello\u00a0World\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$content\u00a0<\/span><span style=\"color: #007700\">.=\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;\/h1&gt;n&lt;\/body&gt;n&lt;\/html&gt;\"<\/span><span style=\"color: #007700\">;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0print\u00a0<\/span><span style=\"color: #0000BB\">$content<\/span><span style=\"color: #007700\">;<\/p>\n<p>\u00a0\u00a0<\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<p><b><br \/>\nEdited for correctness<br \/>\n<\/b><\/p>\n<div class=\"articlePara\">\nWhen run using your web server set up, both scripts will<br \/>\nproduce the following:\n<\/div>\n<div class=\"example\">\n<code><\/p>\n<pre>\n  &lt;html&gt;\n    &lt;head&gt;\n      &lt;title&gt;My First Script&lt;\/title&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n      &lt;h1&gt;Hello World&lt;\/h1&gt;\n    &lt;\/body&gt;\n  &lt;\/html&gt;\n<\/pre>\n<p>    <\/code>\n    <\/div>\n<div class=\"articlePara\">\nMy personal preference is embedding the PHP code within the<br \/>\nHTML code, however there are plenty of alternative theories<br \/>\nout there, and I would encourage you to explore and develop<br \/>\nyour own style of writing scripts.\n<\/div>\n<div class=\"articlePara\">\nAs an example if you ever decide to work with the Typo3<br \/>\nframework (http:\/\/www.typo3.org\/) then you&#8217;ll be highly<br \/>\nlikely to use the Full PHP approach.  For the remainder of<br \/>\nthis series we&#8217;ll be using the embedded HTML approach.\n<\/div>\n<div class=\"articleHeader\">\nThe first script line by line\n<\/div>\n<div class=\"articlePara\">\nAs you can see most PHP statements are included in special<br \/>\nPHP tags which for the most part are no different to regular<br \/>\nHTML tags.\n<\/div>\n<div class=\"articlePara\">\nBecause of this, we can freely use them inter-changeably<br \/>\nanywhere you would use any other HTML tags.\n<\/div>\n<div class=\"articlePara\">\nLooking at the title line in the first example above, you<br \/>\ncan see that we generate the title using PHP code and a<br \/>\nstatic string.  You could use a variable, but since we&#8217;re<br \/>\nnot covering them until next time I&#8217;ll skip over that for<br \/>\nnow.\n<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">1<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"peter_shaw0323094658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"peter_shaw0323094658.html?page=2\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this installment Peter Shaw will show us some simple PHP syntax, and we&#8217;ll write a couple of small scripts to get our feet wet, and get a feel for<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1270","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1270"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":3163,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1270\/revisions\/3163"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}