{"id":643,"date":"2010-02-19T12:35:37","date_gmt":"2010-02-19T17:35:37","guid":{"rendered":"http:\/\/nylinuxhelp.com\/blogs\/?p=643"},"modified":"2010-02-19T12:37:53","modified_gmt":"2010-02-19T17:37:53","slug":"favorite-cli-linux-apps-php5cli","status":"publish","type":"post","link":"https:\/\/nylinuxhelp.com\/blogs\/command-line\/favorite-cli-linux-apps-php5cli","title":{"rendered":"Favorite CLI Linux Apps: php5cli"},"content":{"rendered":"<h2>php5cli runs PHP commands in a shell<\/h2>\n<p>PHP is a scripting language used on many websites.\u00a0 It allows a page to do &#8220;dynamic&#8221; things (such as changing a page&#8217;s appearance based on user input, time or date, etc.)<\/p>\n<p>One of the things I do wtih <strong>php5cli<\/strong> (or php in the shell) is check a PHP script for errors.\u00a0 This saves you the trouble of running your PHP-based web page in a browser (which may have bad side effects).\u00a0 ??Bad side effects?? Sure, what if your page is supposed to overwrite a file, and then hits an error.\u00a0 It may erase a perfectly-good file.\u00a0 Ok, enough gloom and doom talk.\u00a0 Let&#8217;s say you wanted to check &#8220;<em>myPHPscript.php<\/em>&#8221; for errors. Run the following command in a shell to <strong>check it for errors before it runs\/executes<\/strong>.\u00a0 The option is a lowercase L (l) not a digit.<\/p>\n<pre><span style=\"color: #993300;\">php -l myPHPscript.php<\/span>\r\n<\/pre>\n<p>Another good use of PHP in a terminal is to generate HTML code.\u00a0 There&#8217;s a certain frustration in coding up an entire web site, and then needing to go back and make a change across all your pages.\u00a0 A time (and headache) saver is to let PHP do the &#8220;heavy lifting&#8221; for you.\u00a0 What does this mean?<\/p>\n<p>Basically, you set up a series of instructions for a script to follow.\u00a0 Then, based on your needs, you make the script &#8220;write&#8221; different output based on a variable whose value may change.\u00a0 Sometimes this involves changing the size of table cells, but it could apply to writing an entire series of web pages.\u00a0 It comes in way handy when you&#8217;re looping over database results (and deciding to print the 2nd line of an address to the page).<\/p>\n<p>In summary, when you&#8217;d have to change the same attribute in many, many places, and change them a few times, manually finding the attribute (for example a web link), you don&#8217;t have to manually (not mention &#8220;tediously&#8221;) hunt for the item(s) you want to change.\u00a0 <strong>Install php5cli with Synaptic<\/strong> (or other) package manager. This installs any needed dependencies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php5cli runs PHP commands in a shell PHP is a scripting language used on many websites.\u00a0 It allows a page to do &#8220;dynamic&#8221; things (such as changing a page&#8217;s appearance based on user input, time or date, etc.) One of the things I do wtih php5cli (or php in the shell) is check a PHP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,7,53],"tags":[30,48,26,50,54],"class_list":["post-643","post","type-post","status-publish","format-standard","hentry","category-linux-apps","category-command-line","category-web-development","tag-apps","tag-cli","tag-commands","tag-console","tag-php"],"_links":{"self":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/comments?post=643"}],"version-history":[{"count":22,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/643\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/643\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/media?parent=643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/categories?post=643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/tags?post=643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}