Search code examples
phppreg-matchstr-replacepreg-match-all

remove all #EXTM3U from string


I am trying to remove all the #EXTM3U from my big string. My current code doesn't remove anything and gives no result! What i am doing wrong here?

$test_value = preg_match_all("#EXTM3U", "", $input_value);

Solution

  • Your regex doesn't work because you are missing delimiters and aren't using it in a replace context.

    $test_value = preg_replace("/#EXTM3U/", "", $input_value);
    

    should work.

    Furthermore though you aren't using a regex here so a simpler solution would be using str_replace.

    $test_value = str_replace("#EXTM3U", "", $input_value);
    

    Also note $input_value will still have the string you want removed; $test_value will have the string without the #EXTM3U.

    You also might prefer, http://php.net/manual/en/function.str-ireplace.php. If case is unimportant.