Wasabi Posted January 5, 2012 Share Posted January 5, 2012 I have a constant building a dynamic base_url: define('BASE_URL', "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); The current base_url "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php" I've used: echo(BASE_URL . '/index.php' . "<br />"); // Define the URL: echo str_ireplace('htdocs/','', BASE_URL ); //Not the desired result and arrived at: "http://training:8888/php/PHP6:MySQL%205/16/user_registration/test.php" I'm having issues, adapting the str_ireplace() function to remove all segments after "htdocs" so another uri can be appended: $url = BASE_URL . '/somepage.php'; // Define the URL: "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/somepage.php."//Desired result Happy New Year! Link to comment Share on other sites More sharing options...
Larry Posted January 6, 2012 Share Posted January 6, 2012 I really don't understand what you're trying to do here. Also, do you really want a period at the end of the URL as in your desired result? Link to comment Share on other sites More sharing options...
Wasabi Posted January 6, 2012 Author Share Posted January 6, 2012 The "." at the end was not desired I'm trying to trim the result of "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php" to just the requesting directory: "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs" //desired base URL Allowing me to append any document file: $url = BASE_URL . '/somepage.php'; // Define the URL Hope I clarified my request. Thanks for the reply and inspiration. PS: I'm experimenting with http_build_url(); Happy New Year! Link to comment Share on other sites More sharing options...
Larry Posted January 6, 2012 Share Posted January 6, 2012 Okay, that makes more sense, but should it really be "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php" or should that be "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test/index.php". And if it's the latter, should that be trimmed down to "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test/"? Link to comment Share on other sites More sharing options...
Wasabi Posted January 6, 2012 Author Share Posted January 6, 2012 I'm attempting to trim away "test.php" so that I can append "somepage.php". Thus making the base_url usable in any config file. I've seen the same in frameworks, wanting to recreate it "old school." I appreciate frameworks, but still like making apps "from scratch" when time permits, having been with your publications since PHP 4. Thanks Again! Link to comment Share on other sites More sharing options...
Larry Posted January 6, 2012 Share Posted January 6, 2012 So, just to be absolutely clear here, the URL would include BOTH test.php and index.php and you want to strip both? Link to comment Share on other sites More sharing options...
Wasabi Posted January 6, 2012 Author Share Posted January 6, 2012 The $base_url should NOT include test.php, however when using: define('BASE_URL', "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); I get the full path to the requesting document file, I'm trying to strip in this case (test.php), so it can be replaced with $url = BASE_URL . '/whateverpage.php'; Again, thanks for your patience. Link to comment Share on other sites More sharing options...
Larry Posted January 6, 2012 Share Posted January 6, 2012 I think the dirname() function will chop off the file name and return the rest. Link to comment Share on other sites More sharing options...
Wasabi Posted January 7, 2012 Author Share Posted January 7, 2012 I found these forum post with an almost identical query as mine:http://www.webdevelo...ad.php?t=165220 and http://blog.chapagai...in-or-base-url/. If you could add insight to there solutions it would be appreciated. Your patience is appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts