donglu9445
2013-11-03 07:03
浏览 45
已采纳

在http中使用http:// forward slashes str_replace()替换本地路径反斜杠

I get the following result :http://www.example.com/Music/\2011 Hits\Balle Lakka.mp3

Following is str_replace to try and replace local path URL to http:// path:

@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条回答 默认 最新

  • doujiang6944 2013-11-03 07:12
    已采纳

    Can you please try this,

    Simply:

    echo $url = str_replace("/\\","/",$url);
    

    another method,

    $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);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanliaoyin3171 2013-11-03 07:08

    Try something like this

    <?php
    $str='http://www.example.com/Music/\2011 Hits\Balle Lakka.mp3';
    $str=str_replace(array('\\','//',':'),'/',$str);
    echo $str;
    

    OUTPUT:

    http://www.example.com/Music/2011 Hits/Balle Lakka.mp3
    
    评论
    解决 无用
    打赏 举报
  • dsa99349 2013-11-03 07:08
    $file = str_replace('\\','/',$file);
    

    add it to the end. It should work..

    评论
    解决 无用
    打赏 举报
  • dongzi0857 2013-11-03 07:11

    in while loop you can do following:

    while(list($key,$value) = each($data))
        $arr[$i][$key] = ($key!='filename') ? $value : str_replace('\\','/', ltrim($value, '\\'));
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题