CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
Problem:
Your friend is complaining that your website RSS feed is busted and validating with https://validator.w3.org gives this error message :
Sorry
This feed does not validate.
line 3, column 0: XML parsing error:
:3:0: XML or text declaration not at start of entity
Parsing the XML file manually seems to ok and you wonder why the w3.org's validator is not accepting the generated RSS xml? Upon closer inspection, you noticed that there are 2 empty lines above the <?xml
tag. These empty lines caused the validator to mark the RSS or ATOM xml as invalid.
01.
02.
03. <?xml version="1.0" encoding="utf-8"?>
04. <rss version="2.0"
You scanned the PHP and CodeIgniter core files and still unable to discover what caused the empty lines.
Solution:
To remove the empty lines before <?xml
tag, simply add the functions ob_start();
and ob_end_clean();
before generating the XML output.
Example:
ob_start();
ob_end_clean();
header("Content-Type: application/rss+xml");
This should get rid the extra empty lines before the <?xml
tag and validating the RSS/ATOM feed again should be ok now.
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.9k Android Studio : Image button and button example
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+7.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+9.5k Facebook : Getting the friends list with PHP return JSON format
+7.4k Golang : Convert source code to assembly language
+5.7k Golang : Detect words using using consecutive letters in a given string
+6k Golang : Extract unicode string from another unicode string example
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+11.6k Golang : Surveillance with web camera and OpenCV
+9.9k Golang : Sort and reverse sort a slice of integers