我得到以下结果:http://www.example.com/Music/\2011 Hits\Balle Lakka.mp3
以下str_replace
尝试将本地路径网址替换为http://
路径:
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT songlist.* FROM songlist WHERE ID='".$song->ID."'";
$result = mysql_query($query,$conn);
$i=0;
while($data = mysql_fetch_assoc($result))
{
while(list($key,$value) = each($data))
$arr[$i][$key] = $value;
$i++;
}
$file = str_replace("C:\inetpub\Music","http://www.example.com/Music/",$arr[0]['filename']);
答案 0 :(得分:1)
$file = str_replace('\\','/',$file);
将其添加到最后。它应该工作..
答案 1 :(得分:0)
尝试这样的事情
<?php
$str='http://www.example.com/Music/\2011 Hits\Balle Lakka.mp3';
$str=str_replace(array('\\','//',':'),'/',$str);
echo $str;
<强>输出:强>
http://www.example.com/Music/2011 Hits/Balle Lakka.mp3
答案 2 :(得分:0)
在while循环中,您可以执行以下操作:
while(list($key,$value) = each($data))
$arr[$i][$key] = ($key!='filename') ? $value : str_replace('\\','/', ltrim($value, '\\'));
答案 3 :(得分:0)
你能试试吗,
简单地说:
echo $url = str_replace("/\\","/",$url);
另一种方法,
$url = str_replace("C:\inetpub\Music","http://www.mydomain.com/Music/","http://www.mydomain.com/Music/2011 Hits/\Balle Lakka.mp3");
$url = str_replace("\\","/",$url);
$url = str_replace("//","/",$url);
echo $url = str_replace("http:/","http://",$url);