{"id":93,"date":"2005-12-14T11:58:43","date_gmt":"2005-12-14T16:58:43","guid":{"rendered":"https:\/\/vitaluna.net\/wordpress\/?p=93"},"modified":"2005-12-14T11:58:43","modified_gmt":"2005-12-14T16:58:43","slug":"simple-text-entry-with-php","status":"publish","type":"post","link":"https:\/\/vitaluna.net\/?p=93","title":{"rendered":"Simple text entry with PHP"},"content":{"rendered":"<p>I&#8217;m on a new path to get better at PHP\/MySQL, now that we&#8217;ve got a new programmer on staff, and I can abuse him as a resource. A cool snipped for poor-man&#8217;s content management is what I came up with today. If you have a text file that a user wants to edit, but also wants to strip the pesky slashes from, and interpret carriage returns when writing the file, here&#8217;s what I came up with. It also prints the file&#8217;s modification date as an &#8220;Updated last&#8221; line:<\/p>\n<p>&lt;?<br \/>\n\/\/Declare the session variable value<br \/>\nsession_start();<br \/>\n\/\/declare the report variable<br \/>\nif(isset($_POST[&#8216;report&#8217;]))<br \/>\n{<br \/>\n$report = str_replace(&quot;\\r\\n&quot;, &quot;&lt;br&gt;&quot;, $_POST[&#8216;report&#8217;]);<\/p>\n<p>\/\/declare and open the file for writing<br \/>\n$myfile = &quot;myfile.txt&quot;;<br \/>\n$fh = fopen($myfile, &#8216;w&#8217;) or die(&quot;can&#8217;t open file&quot;);<\/p>\n<p>\/\/write the form data to the report<br \/>\nfwrite($fh, (stripslashes($report)));<br \/>\nfclose($fh);<br \/>\n}<br \/>\n?&gt;\n<\/p>\n<p>Then we have the printed text, as well as the form, rolled into one file:<\/p>\n<p>&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;p&gt;<br \/>\n&lt;? \t\techo date( &quot;F d\\, Y&quot;, filemtime(&#8216;myfile.txt&#8217;) ).&quot; &#8211; Last updated&quot;; \t?&gt;<br \/>\n&lt;\/p&gt;<\/p>\n<p>&lt;p&gt;<br \/>\n&lt;? include(&#8216;myfile.txt&#8217;); ?&gt;<br \/>\n&lt;\/p&gt;<\/p>\n<p>&lt;p&gt;Write the daily report:&lt;br&gt;<\/p>\n<p>&lt;form action=&quot;&lt;? echo $PHP_SELF ?&gt;&quot; method=&quot;post&quot; name=&quot;report&quot;&gt;<br \/>\n&lt;textarea name=&quot;report&quot; rows=&quot;9&quot; cols=&quot;94&quot;&gt;&lt;\/textarea&gt;&lt;br&gt;<br \/>\n&lt;input type=&quot;submit&quot; name=&quot;submitButtonName&quot;&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n|&lt;\/html&gt;<\/p>\n<p>PHP kicks bum.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m on a new path to get better at PHP\/MySQL, now that we&#8217;ve got a new programmer on staff, and I can abuse him as a resource. A cool snipped for poor-man&#8217;s content management is what I came up with today. If you have a text file that a user wants to edit, but also&hellip; <a class=\"more-link\" href=\"https:\/\/vitaluna.net\/?p=93\">Continue reading <span class=\"screen-reader-text\">Simple text entry with PHP<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-tech-bytes","entry"],"_links":{"self":[{"href":"https:\/\/vitaluna.net\/index.php?rest_route=\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vitaluna.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vitaluna.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vitaluna.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/vitaluna.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93"}],"version-history":[{"count":0,"href":"https:\/\/vitaluna.net\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions"}],"wp:attachment":[{"href":"https:\/\/vitaluna.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vitaluna.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vitaluna.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}