我得到这个代码问题从转换路径字符串 “/”, “”
$ =的current_path str_replace函数( '\', '/',GETCWD()); // c:// xampp/htdoc
为什么它无法在目录补丁中用'/'替换'\'?为什么是这个原因以及如何处理这个问题?
编辑此代码用于返回路径(或类似的东西)使用HTML标记基地。代替\
作为
$current_path = getcwd(); function get_basepath() { global $current_path; $current_path = str_replace('\\', '/', $current_path); // C:\xampp\htdocs\php\gettingstarted $cur_root = $_SERVER['HTTP_HOST']; // localhost $cur_docroot = $_SERVER['DOCUMENT_ROOT']; // C:/xampp/htdocs/ $cur_filepath = $_SERVER['SCRIPT_FILENAME']; // C:/xampp/htdocs/php/gettingstarted/index.php $filepath = str_replace($cur_docroot, '', $current_path); return "http://$cur_root/" . $filepath . "/"; // http://localhost/php/gettingstarted/index1.php }
是的,我忘记了。非常感谢你 – justjoe 2010-03-27 13:16:33