You are here:


PHP XML and CSV Parser - Magic Parser

A PHP library for feed format auto-detection and processing.

Parse just about any XML or CSV variant datafeed in PHP. Originally designed for working with affiliate product feeds it led to the development of Price Tapestry - a price comparison script for PHP and MySQL...

example1.php

<?php
  
require("MagicParser.php");
  
$url "https://feeds.bbci.co.uk/news/rss.xml?edition=uk";
  
$formatString MagicParser_getFormat($url);
  print 
$formatString.PHP_EOL;
?>

$php example1.php
xml|RSS/CHANNEL/ITEM/

example2.php

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
  }
  
$url "https://feeds.bbci.co.uk/news/rss.xml?edition=uk";
  
$formatString "xml|RSS/CHANNEL/ITEM/";
  
MagicParser_parse($url,"myRecordHandler",$formatString);
?>

$php example2.php
...
Array
(
    [ITEM] =>
    [TITLE] => World Cup 2022: How to follow England's quarter-final with France
    [DESCRIPTION] => England will take on France in a mouth-watering World Cup...
    [LINK] => https://www.bbc.co.uk/sport/football/63843056?at_medium=RSS&at_campaign=KARANGA
    [GUID] => https://www.bbc.co.uk/sport/football/63843056
    [GUID-ISPERMALINK] => false
    [PUBDATE] => Sun, 04 Dec 2022 20:53:37 GMT
)
...