dqnek0079 2017-03-22 06:43
浏览 29
已采纳

如何从我的PHP中删除空格

When I run my php code it shows the content perfectly, but there's a space after start and before stop. How do I remove all spaces? I thought that's what I was doing with trim?

    <?php
function getURL($u){
    $ops = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Accept: text/html
" .
                  "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
"
      )
    );
    $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 
  • 写回答

2条回答 默认 最新

  • drsc10888 2017-03-22 06:54
    关注

    You should trim all the whitespace characters, like this:

    start<?= trim($stream, "
    \t ")?>stop
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码