{"id":228,"date":"2010-08-27T01:03:26","date_gmt":"2010-08-27T01:03:26","guid":{"rendered":"http:\/\/soliloquyforthefallen.net\/blog\/?p=228"},"modified":"2015-03-05T07:18:07","modified_gmt":"2015-03-05T07:18:07","slug":"quick-php-note","status":"publish","type":"post","link":"https:\/\/soliloquyforthefallen.net\/?p=228","title":{"rendered":"Quick PHP Note"},"content":{"rendered":"<p>I&#8217;ve been busy hacking the code on somebody&#8217;s site.\u00a0 I just wanna mention the fopen command in PHP.\u00a0 And how you shouldn&#8217;t use it.\u00a0 It&#8217;s frightfully frail, and there&#8217;s little to no information on how to make it work.\u00a0 And sometimes webhosts disable it in the php.ini config, so it doesn&#8217;t always work. \u00a0\u00a0 Use $data = file_get_contents(&#8220;some_random_file.file&#8221;) instead to put the contents int a variable.\u00a0 If you need to make an array from it,$ array = explode (&#8220;n&#8221;, $data);\u00a0 instead of fget.\u00a0 Then call $items_in_array= count($array) &#8211; 1; to get the total number of items in the array.\u00a0 Its a little more wordy, but I think has the same number of lines as the while() loop would require.<\/p>\n<p>Just don&#8217;t use fopen.\u00a0 Please.\u00a0 Its buggy at best, and possible maybe seemingly unusable in wordpress.\u00a0 Which is why I had to convert my code from using fopen to file_get_contents.<\/p>\n<p>One more note.\u00a0 A function&#8217;s &#8220;present working directory&#8221; in wordpress is the directory it&#8217;s installed to.\u00a0 echo getcwd(); as proof \ud83d\ude42\u00a0 Which, if I say so myself and I will is stupid.\u00a0 Total stupid.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been busy hacking the code on somebody&#8217;s site.\u00a0 I just wanna mention the fopen command in PHP.\u00a0 And how you shouldn&#8217;t use it.\u00a0 It&#8217;s frightfully frail, and there&#8217;s little to no information on how to make it work.\u00a0 And sometimes webhosts disable it in the php.ini config, so it doesn&#8217;t always work. \u00a0\u00a0 Use&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/soliloquyforthefallen.net\/?p=228\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[117],"tags":[],"_links":{"self":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/228"}],"collection":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":1,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":767,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/767"}],"wp:attachment":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}