How do I remove  from the beginning of a file?

前端 未结 23 1334
攒了一身酷
攒了一身酷 2020-11-22 06:21

I have a CSS file that looks fine when I open it using gedit, but when it\'s read by PHP (to merge all the CSS files into one), this CSS has the following characters prepend

23条回答
  •  青春惊慌失措
    2020-11-22 06:49

    Same problem, different solution.

    One line in the PHP file was printing out XML headers (which use the same begin/end tags as PHP). Looks like the code within these tags set the encoding, and was executed within PHP which resulted in the strange characters. Either way here's the solution:

    # Original
    $xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    
    # fixed
    $xml_string = "<" . "?xml version=\"1.0\" encoding=\"UTF-8\"?" . ">";
    

提交回复
热议问题