当我运行我的PHP代码时,它完美地显示了内容,但是在开始之后和停止之前有一个空格。如何删除所有空格?我认为这就是我用trim
做的事情?
<?php
function getURL($u){
$ops = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: text/html\r\n" .
"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0\r\n"
)
);
$co = stream_context_create($ops);
$r = file_get_contents('http://' . $u, false, $co);
return $r != false ? $r : "";
}
function GetStringBetween($string, $start, $finish){
$string = " ".$string;
$position = strpos($string, $start);
if ($position == 0) return "";
$position += strlen($start);
$length = strpos($string, $finish, $position) - $position;
return substr($string, $position, $length);
}
$grab = file_get_contents('myurl');
$m3u8 = file_get_contents( trim($grab) );
$stream = GetStringBetween($m3u8, 'start"', '#stop');
?>
start<?=$stream?>stop
答案 0 :(得分:1)
你应该修剪所有空格字符,如下所示:
start<?= trim($stream, "\r\n\t ")?>stop
答案 1 :(得分:0)
要仅删除空格,请使用str_replace
。对于包含空格的空格字符,选项卡...使用preg_replace
$string = preg_replace('/\s+/','',$string);