{"id":330181,"date":"2010-02-17T06:45:43","date_gmt":"2010-02-17T10:45:43","guid":{"rendered":"http:\/\/www.icantinternet.org\/?p=555"},"modified":"2010-02-17T06:45:43","modified_gmt":"2010-02-17T10:45:43","slug":"php-lesson-1-general-introduction","status":"publish","type":"post","link":"https:\/\/mereja.media\/index\/330181","title":{"rendered":"PHP Lesson 1: General Introduction"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\">What is PHP?<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright\" title=\"PHP tutorial\" src=\"http:\/\/farm3.static.flickr.com\/2294\/2265073019_c7376a2509.jpg\" alt=\"PHP tutorial\" width=\"350\" height=\"234\" \/>PHP is a scripting language, primarily intended to generate dynamical websites on a webserver. PHP is designed in 1994, by a senior software engineer at IBM, Rasmus Lerdorf, and the language was clearly inspired by Perl. The letters PHP used to mean Personal Homepage (or more complete: Personal Home Page\/Forms Interpreter, PHP\/FI). However, during the later developments, PHP became a recursive acronym, meaning &#8220;PHP: Hypertext Preprocessor&#8221;, which better suits what the language actually does: outputting hypertext (HTML or XHTML).<br \/>\nSince PHP is a server side scripting language, it means that the code is not compiled, but interpreted at the time of usage (by the interpreter, most often integrated in the webserver), and that the script runs on the server side, or the webserver. This way, the output is generated on the webserver, and sent to the client (your browser) as HTML.<br \/>\nPHP syntax is derived from many other languages, but mainly by C and Perl. However, since PHP5 also allows for object oriented programming, there is also an influence of Java noticeable. Despite all these different influences, PHP manages to remain simple and understandable.<\/p>\n<p><span style=\"text-decoration: underline;\">The Source and the Tags<\/span><\/p>\n<p>Although PHP is primarily intended as a text processor, it is often used as a pure programming language. However, to facilitate its text processor role, it can be inserted in a text file as well, by using the special PHP tags. Four different tags can be used to insert and execute PHP code in a text file:<\/p>\n<ul>\n<p style=\"padding-left: 30px;\">\n<li> Standard tags, these are the most commonly used tags, and are the ones you should use:<br \/>\n<em>&lt;?php<br \/>\n&#8230;<br \/>\n?&gt;<\/em><\/p>\n<p style=\"padding-left: 30px;\">\n<\/li>\n<li> Short tags, used to be the standard, but might interfere with XML headers, and therefor are used more rarely:<br \/>\n<em>&lt;?<br \/>\n&#8230;<br \/>\n?&gt;<\/em><\/p>\n<p style=\"padding-left: 30px;\">One advantage is that they make really short syntax possible, such as &lt;?=$variable ?&gt; which prints the result of the variable straight to the output.<\/p>\n<p style=\"padding-left: 30px;\">\n<\/li>\n<li> Script tags were introduced for HTML editors. These editors are programmed to ignore JavaScript code (which uses the same script tags), but were unable to ignore PHP code, which is fixed by these script tags:<br \/>\n<em>&lt;script language=&#8221;PHP&#8221;&gt;<br \/>\n&#8230;<br \/>\n&lt;\/script&gt;<\/em><\/p>\n<p style=\"padding-left: 30px;\">\n<\/li>\n<li> ASP tags, don&#8217;t ask, nobody seems to know why these were introduced&#8230;<br \/>\n<em>&lt;%<br \/>\n&#8230;<br \/>\n%&gt;<\/em><\/li>\n<\/ul>\n<p>Normally, the only tags you should use are the standard tags. Short tags, script tags and ASP tags are all considered deprecated.<\/p>\n<p><span style=\"text-decoration: underline;\">The newline horror<\/span><\/p>\n<p>Very important to remember is that the PHP interpreter outputs EVERY character outside the PHP tags as-is. This means every whitespace, every newline character. This is not an issue for whitespaces, but can be for newline characters, as they are used as a seperator between the header portion of the http response, and the actual data. This means that a newline character that is sent to the output before the headers are finished, will cause your script to fail. To help you prevent this problem, the PHP interpreter automatically strip the first newline character after the PHP closing tag (?&gt;).<\/p>\n<p><span style=\"text-decoration: underline;\">The body of a PHP script<\/span><\/p>\n<p>The body of a PHP script consists of statements, which can be function calls, variable assignments, data output etcetera. Each statement, with only a few exceptions, needs to be terminated by a semicolon. One of the exceptions is for instance the last statement before a closing tag. However, for consistency&#8217;s sake, it is advised to always terminate your statements.<\/p>\n<p>Comments are another almost vital part of any programming language. Yes, I know, they are not vital at all, but you should treat them like that. Make it a habit to write comments every function, class, method or property that you write in your code. If your code required some thinking to find how you will actually code it, it will require some thinking again later when you try to reread your code, and find out why you actually coded it that way. Comments can only make your life easier!<br \/>\nThe different ways of inserting comments in a PHP script are these:<\/p>\n<p style=\"padding-left: 30px;\"><em>\/\/ a single line comment<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em># another single line comment<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>\/* a multiline<br \/>\ncomment<br \/>\n*\/<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>\/**<br \/>\n* another multiline comment<br \/>\n* Most often used to document API&#8217;s or functions, since they can hold large parts of structured text<br \/>\n* and still look&#8230; err&#8230; structured.<br \/>\n*\/<br \/>\n<\/em><br \/>\nBoth single line comments (\/\/ and #) are closed by a newline character, or by the PHP closing tag.<\/p>\n<p>Code blocks are a series of statements that must be executed all together, and under specific circumstances, such as a function call or a conditional statement. The statements inside code blocks are enclosed with two curly brackets ({}).<\/p>\n<p style=\"padding-left: 30px;\"><em>if ($whatimsaying == &#8220;yaddayadda&#8221;)<br \/>\nthen<br \/>\n{<br \/>\n$takeanapforsometime = 5;<br \/>\nfall_asleep_for_how_long($takenapforsometime);<br \/>\n}<br \/>\n<\/em><\/p>\n<p>That&#8217;s all for today folks. More is coming up in the next lesson, which will start with Datatypes!<\/p>\n<p><!-- Begin SexyBookmarks Menu Code --><\/p>\n<div class=\"sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy\">\n<ul class=\"socials\">\n<li class=\"sexy-delicious\">\n\t\t\t<a href=\"http:\/\/del.icio.us\/post?url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Share this on del.icio.us\">Share this on del.icio.us<\/a>\n\t\t<\/li>\n<li class=\"sexy-digg\">\n\t\t\t<a href=\"http:\/\/digg.com\/submit?phase=2&amp;url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Digg this!\">Digg this!<\/a>\n\t\t<\/li>\n<li class=\"sexy-reddit\">\n\t\t\t<a href=\"http:\/\/reddit.com\/submit?url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Share this on Reddit\">Share this on Reddit<\/a>\n\t\t<\/li>\n<li class=\"sexy-yahoobuzz\">\n\t\t\t<a href=\"http:\/\/buzz.yahoo.com\/submit\/?submitUrl=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;submitHeadline=PHP+Lesson+1%3A+General+Introduction&amp;submitSummary=What%20is%20PHP%3F%0D%0A%0D%0APHP%20is%20a%20scripting%20language%2C%20primarily%20intended%20to%20generate%20dynamical%20websites%20on%20a%20webserver.%20PHP%20is%20designed%20in%201994%2C%20by%20a%20senior%20software%20engineer%20at%20IBM%2C%20Rasmus%20Lerdorf%2C%20and%20the%20language%20was%20clearly%20inspired%20by%20Perl.%20The%20letters%20PHP%20used%20to%20mean%20Personal%20Homepage%20%28or%20more%20complet&amp;submitCategory=science&amp;submitAssetType=text\" rel=\"\" class=\"external\" title=\"Buzz up!\">Buzz up!<\/a>\n\t\t<\/li>\n<li class=\"sexy-stumbleupon\">\n\t\t\t<a href=\"http:\/\/www.stumbleupon.com\/submit?url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Stumble upon something good? Share it on StumbleUpon\">Stumble upon something good? Share it on StumbleUpon<\/a>\n\t\t<\/li>\n<li class=\"sexy-technorati\">\n\t\t\t<a href=\"http:\/\/technorati.com\/faves?add=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/\" rel=\"\" class=\"external\" title=\"Share this on Technorati\">Share this on Technorati<\/a>\n\t\t<\/li>\n<li class=\"sexy-mixx\">\n\t\t\t<a href=\"http:\/\/www.mixx.com\/submit?page_url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Share this on Mixx\">Share this on Mixx<\/a>\n\t\t<\/li>\n<li class=\"sexy-facebook\">\n\t\t\t<a href=\"http:\/\/www.facebook.com\/share.php?v=4&amp;src=bm&amp;u=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;t=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Share this on Facebook\">Share this on Facebook<\/a>\n\t\t<\/li>\n<li class=\"sexy-twitter\">\n\t\t\t<a href=\"http:\/\/twitter.com\/home?status=PHP+Lesson+1%3A+General+Introduction+-+http:\/\/b2l.me\/gkvsa+(via+@Icantinternet)\" rel=\"\" class=\"external\" title=\"Tweet This!\">Tweet This!<\/a>\n\t\t<\/li>\n<li class=\"sexy-comfeed\">\n\t\t\t<a href=\"http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/feed\" rel=\"\" class=\"external\" title=\"Subscribe to the comments for this post?\">Subscribe to the comments for this post?<\/a>\n\t\t<\/li>\n<li class=\"sexy-linkedin\">\n\t\t\t<a href=\"http:\/\/www.linkedin.com\/shareArticle?mini=true&amp;url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction&amp;summary=What%20is%20PHP%3F%0D%0A%0D%0APHP%20is%20a%20scripting%20language%2C%20primarily%20intended%20to%20generate%20dynamical%20websites%20on%20a%20webserver.%20PHP%20is%20designed%20in%201994%2C%20by%20a%20senior%20software%20engineer%20at%20IBM%2C%20Rasmus%20Lerdorf%2C%20and%20the%20language%20was%20clearly%20inspired%20by%20Perl.%20The%20letters%20PHP%20used%20to%20mean%20Personal%20Homepage%20%28or%20more%20complet&amp;source=iCan&#039;t%20Internet\" rel=\"\" class=\"external\" title=\"Share this on Linkedin\">Share this on Linkedin<\/a>\n\t\t<\/li>\n<li class=\"sexy-blogmarks\">\n\t\t\t<a href=\"http:\/\/blogmarks.net\/my\/new.php?mini=1&amp;simple=1&amp;url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/&amp;title=PHP+Lesson+1%3A+General+Introduction\" rel=\"\" class=\"external\" title=\"Mark this on BlogMarks\">Mark this on BlogMarks<\/a>\n\t\t<\/li>\n<li class=\"sexy-blogengage\">\n\t\t\t<a href=\"http:\/\/www.blogengage.com\/submit.php?url=http:\/\/www.icantinternet.org\/2010\/02\/php-lesson-1-general-introduction\/\" rel=\"\" class=\"external\" title=\"Engage with this article!\">Engage with this article!<\/a>\n\t\t<\/li>\n<\/ul>\n<div style=\"clear:both;\"><\/div>\n<\/div>\n<p><!-- End SexyBookmarks Menu Code --><\/p>\n<p>Related posts:<\/p>\n<ol>\n<li><a href='http:\/\/www.icantinternet.org\/2010\/04\/php-lesson-3-variables-and-constants\/' rel='bookmark' title='Permanent Link: PHP Lesson 3: Variables and Constants'>PHP Lesson 3: Variables and Constants<\/a> <small>Variables Variables are containers, they contain data. PHP is a&#8230;<\/small><\/li>\n<li><a href='http:\/\/www.icantinternet.org\/2010\/03\/php-lesson-2-data-types\/' rel='bookmark' title='Permanent Link: PHP Lesson 2: Data types'>PHP Lesson 2: Data types<\/a> <small>Today&#8217;s PHP lesson is about data types. Although PHP can&#8230;<\/small><\/li>\n<li><a href='http:\/\/www.icantinternet.org\/2008\/03\/regular-expressions-cheatsheet\/' rel='bookmark' title='Permanent Link: Regular Expressions Cheatsheet'>Regular Expressions Cheatsheet<\/a> <small> ^ Start of string \\A Start of string $&#8230;<\/small><\/li>\n<\/ol>\n<p><a href=\"http:\/\/feedads.g.doubleclick.net\/~a\/QYSnbppgHAJ9_tn_Pd2xyGeCetg\/0\/da\"><img decoding=\"async\" src=\"http:\/\/feedads.g.doubleclick.net\/~a\/QYSnbppgHAJ9_tn_Pd2xyGeCetg\/0\/di\" border=\"0\" ismap=\"true\"><\/img><\/a><br \/>\n<a href=\"http:\/\/feedads.g.doubleclick.net\/~a\/QYSnbppgHAJ9_tn_Pd2xyGeCetg\/1\/da\"><img decoding=\"async\" src=\"http:\/\/feedads.g.doubleclick.net\/~a\/QYSnbppgHAJ9_tn_Pd2xyGeCetg\/1\/di\" border=\"0\" ismap=\"true\"><\/img><\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/feeds.feedburner.com\/~r\/IcantInternet\/~4\/G2RQTvfV0XA\" height=\"1\" width=\"1\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is PHP? PHP is a scripting language, primarily intended to generate dynamical websites on a webserver. PHP is designed in 1994, by a senior software engineer at IBM, Rasmus Lerdorf, and the language was clearly inspired by Perl. The letters PHP used to mean Personal Homepage (or more complete: Personal Home Page\/Forms Interpreter, PHP\/FI). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,7],"tags":[],"class_list":["post-330181","post","type-post","status-publish","format-standard","hentry","category-internet","category-news"],"_links":{"self":[{"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/posts\/330181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/comments?post=330181"}],"version-history":[{"count":0,"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/posts\/330181\/revisions"}],"wp:attachment":[{"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/media?parent=330181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/categories?post=330181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mereja.media\/index\/wp-json\/wp\/v2\/tags?post=330181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}