![](/img/trans.png)
[英]Replacing backslashes with forward slashes with str_replace() in php
[英]Replacing local path backslashes with http:// forward slashes str_replace() in php
我得到以下結果: http://www.example.com/Music/\\2011 Hits\\Balle Lakka.mp3
: 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']);
$file = str_replace('\\','/',$file);
將其添加到末尾。 它應該工作..
試試這個
<?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
在while循環中,您可以執行以下操作:
while(list($key,$value) = each($data))
$arr[$i][$key] = ($key!='filename') ? $value : str_replace('\\','/', ltrim($value, '\\'));
你能試試看嗎
只是:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.