Skip to content
Advertisement

How to remove spaces from my 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/htmlrn" .
                  "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0rn"
      )
    );
    $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 

Advertisement

Answer

You should trim all the whitespace characters, like this:

start<?= trim($stream, "rnt ")?>stop
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement