0

我得到以下结果:http://www.example.com/Music/\2011 Hits\Balle Lakka.mp3

以下是str_replace尝试将本地路径 URL 替换为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']);
4

4 回答 4

1
$file = str_replace('\\','/',$file);

将其添加到末尾。它应该工作..

于 2013-11-03T07:08:40.453 回答
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
于 2013-11-03T07:08:01.527 回答
0

在 while 循环中,您可以执行以下操作:

while(list($key,$value) = each($data))
    $arr[$i][$key] = ($key!='filename') ? $value : str_replace('\\','/', ltrim($value, '\\'));
于 2013-11-03T07:11:29.197 回答
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);
于 2013-11-03T07:12:54.670 回答