{"id":800,"date":"2009-04-15T23:16:15","date_gmt":"2009-04-15T23:16:15","guid":{"rendered":"http:\/\/markandkelley.com\/mark\/?p=155"},"modified":"2012-01-30T02:43:55","modified_gmt":"2012-01-30T02:43:55","slug":"php-url-to-file-path","status":"publish","type":"post","link":"https:\/\/www.hickendesign.com\/site\/2009\/04\/php-url-to-file-path\/","title":{"rendered":"PHP URL to File Path"},"content":{"rendered":"<p>I don&#8217;t know why it was so hard to find some code to do this.\u00a0 I did a few google searches and couldn&#8217;t find a simple solution so here&#8217;s one that works&#8230;<\/p>\n<pre><code>function mh_UrlToFilePath($url=\"\") {\r\n&nbsp;&nbsp;$sServerName = $_SERVER[\"SERVER_NAME\"];\r\n&nbsp;&nbsp;$sDocRoot = $_SERVER['DOCUMENT_ROOT'];\r\n&nbsp;&nbsp;$sUrl = substr($url, 0, strpos($url, \"?\")); \/\/ remove querystring\r\n&nbsp;&nbsp;$sFilePath = substr($sUrl,strpos($sUrl,$sServerName)+strlen($sServerName));\r\n&nbsp;&nbsp;$sFilePath = $sDocRoot . $sFilePath;\r\n&nbsp;&nbsp;$sFilePath = str_replace(\"\/\", \"\\\", $sFilePath);\r\n&nbsp;&nbsp;return $sFilePath;\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t know why it was so hard to find some code to do this.\u00a0 I did a few google searches and couldn&#8217;t find a simple solution so here&#8217;s one that works&#8230; function mh_UrlToFilePath($url=&#8221;&#8221;) { &nbsp;&nbsp;$sServerName = $_SERVER[&#8220;SERVER_NAME&#8221;]; &nbsp;&nbsp;$sDocRoot = $_SERVER[&#8216;DOCUMENT_ROOT&#8217;]; &nbsp;&nbsp;$sUrl = substr($url, 0, strpos($url, &#8220;?&#8221;)); \/\/ remove querystring &nbsp;&nbsp;$sFilePath = substr($sUrl,strpos($sUrl,$sServerName)+strlen($sServerName)); &nbsp;&nbsp;$sFilePath = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.hickendesign.com\/site\/2009\/04\/php-url-to-file-path\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;PHP URL to File Path&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-800","post","type-post","status-publish","format-standard","hentry","category-general-posts"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/posts\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":3,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":924,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/posts\/800\/revisions\/924"}],"wp:attachment":[{"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hickendesign.com\/site\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}