{"id":50785,"date":"2020-11-06T03:01:24","date_gmt":"2020-11-05T17:01:24","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=50785"},"modified":"2020-11-06T10:30:28","modified_gmt":"2020-11-06T00:30:28","slug":"php-passthru-output-buffering-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-passthru-output-buffering-primer-tutorial\/","title":{"rendered":"PHP Passthru Output Buffering Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/whatis.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Passthru Output Buffering Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/whatis.jpg\" title=\"PHP Passthru Output Buffering Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Passthru Output Buffering Primer Tutorial<\/p><\/div>\n<p>The PHP <a target=_blank title='PHP passthru() method information' href='http:\/\/php.net\/manual\/en\/function.passthru.php'><i>passthru<\/i><\/a> command &#8230;<\/p>\n<blockquote cite='https:\/\/www.php.net\/manual\/en\/function.passthru.php'><p>\nExecute an external program and display raw output\n<\/p><\/blockquote>\n<p> &#8230; is a good way for your underlying command line be expressed within a PHP web application executed in a web browser.<\/p>\n<p>But that &#8220;raw&#8221; above is just that, very &#8220;raw&#8221; in that the neat reports you see with Linux and macOS commands (at the command line) will not show that neatly just by using &#8220;passthru&#8221;.<\/p>\n<p>But you can use PHP output buffers <font color=blue>as per<\/font> <font size=1 color=red>(but there&#8217;s more)<\/font> &#8230;<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n \/\/ whatis.php<br \/>\n \/\/ Supervise whatis command<br \/>\n \/\/ November, 2020<br \/>\n if (isset($_GET['insearch'])) {<br \/>\n   if (urldecode($_GET['insearch']) == '') {<br \/>\n     echo \"&lt;html&gt;&lt;body onload=\\\" document.getElementById('insearch').focus(); \\\"&gt;&lt;h1&gt;Supervise whatis command&lt;\/h1&gt;&lt;h3&gt;RJM Programming - November, 2020&lt;\/h3&gt;&lt;br&gt;&lt;br&gt;&lt;form action=.\/whatis.php method=GET&gt;&lt;input placeholder='Enter whatis object' type=text id=insearch name=insearch value=''&gt;&lt;\/input&gt;&nbsp;&lt;input type=submit value=Go&gt;&lt;\/input&gt;&lt;\/form&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n   } else {<br \/>\n     <font color=blue><a target=_blank title='PHP ob_start method information' href='http:\/\/php.net\/manual\/en\/function.ob-start.php'>ob_start<\/a>();<\/font><br \/>\n     passthru(\"whatis \" . <font color=red>explode(\"\\n\",explode(\"\\r\",explode(\";\",<\/font>explode(\"&lt;\",explode(\"&gt;\",explode(\"|\",str_replace(\"+\",\" \",urldecode($_GET['insearch'])))[0])[0])[0]<font color=red>)[0])[0])[0]<\/font>);<br \/>\n     <font color=blue>$var = <a target=_blank title='PHP ob_get_contents method information' href='http:\/\/php.net\/manual\/en\/function.ob-get-contents.php'>ob_get_contents<\/a>();<br \/>\n     <a target=_blank title='PHP ob_end_clean method information' href='http:\/\/php.net\/manual\/en\/function.ob-end-clean.php'>ob_end_clean<\/a>();<\/font><br \/>\n     echo \"&lt;html&gt;&lt;body onload=\\\" document.getElementById('insearch').focus(); \\\"&gt;&lt;pre&gt;\" . <font color=blue>\"$ whatis \" . <font color=red>explode(\"\\n\",explode(\"\\r\",explode(\";\",<\/font>explode(\"&lt;\",explode(\"&gt;\",explode(\"|\",str_replace(\"+\",\" \",urldecode($_GET['insearch'])))[0])[0])[0]<font color=red>)[0])[0])[0]<\/font> . \"&lt;br&gt;\" . str_replace(\"\\n\", \"&lt;br&gt;\", $var)<\/font> . \"&lt;\/pre&gt;&lt;br&gt;&lt;br&gt;&lt;h1&gt;Supervise whatis command&lt;\/h1&gt;&lt;h3&gt;RJM Programming - November, 2020&lt;\/h3&gt;&lt;br&gt;&lt;br&gt;&lt;form action=.\/whatis.php method=GET&gt;&lt;input placeholder='Enter whatis object' type=text id=insearch name=insearch value=''&gt;&lt;\/input&gt;&nbsp;&lt;input type=submit value=Go&gt;&lt;\/input&gt;&lt;\/form&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n     exit;<br \/>\n   }<br \/>\n } else {<br \/>\n   echo \"&lt;html&gt;&lt;body onload=\\\" document.getElementById('insearch').focus(); \\\"&gt;&lt;h1&gt;Supervise whatis command&lt;\/h1&gt;&lt;h3&gt;RJM Programming - November, 2020&lt;\/h3&gt;&lt;br&gt;&lt;br&gt;&lt;form action=.\/whatis.php method=GET&gt;&lt;input placeholder='Enter whatis object' type=text id=insearch name=insearch value=''&gt;&lt;\/input&gt;&nbsp;&lt;input type=submit value=Go&gt;&lt;\/input&gt;&lt;\/form&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n }<br \/>\n<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; to effectively reinstate those carriage return\/line feeds that make the &#8220;passthru&#8221; (underlying operating system) commands those neat reports appealing to our eyes.<\/p>\n<p>Better on a local <a target=_blank title='MAMP for Apache\/PHP\/MySql on Mac OS X local web server' href='http:\/\/www.mamp.info'><i>MAMP<\/i><\/a> web server (under macOS operating system) is today&#8217;s proof of concept <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/whatis.php_GETME\" title=\"whatis.php\">whatis.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/whatis.php\" title=\"Click picture\">&#8220;whatis&#8221; command supervisor<\/a> PHP web application for you to try out (or perhaps download to a local web server).<\/p>\n<p><i><b><font color=red>Stop Press<\/font><\/b><\/i><\/p>\n<p><font color=red>Oops!<\/font><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50785' onclick='var dv=document.getElementById(\"d50785\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/passthru\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50785' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The PHP passthru command &#8230; Execute an external program and display raw output &#8230; is a good way for your underlying command line be expressed within a PHP web application executed in a web browser. But that &#8220;raw&#8221; above is &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-passthru-output-buffering-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[168,234,744,3467,853,3468,2427,932,997,1200,1319,3469],"class_list":["post-50785","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-buffer","tag-command-line","tag-mamp","tag-ob_get_contents","tag-ob_start","tag-output-buffer","tag-passthru","tag-php","tag-programming","tag-stop-press","tag-tutorial","tag-whatis"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50785"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=50785"}],"version-history":[{"count":11,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50785\/revisions"}],"predecessor-version":[{"id":50796,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50785\/revisions\/50796"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=50785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=50785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=50785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}