You are here:  » Problem with &

Support Forum



Problem with &

Submitted by jopsu on Mon, 2009-01-26 13:24 in

Hi,

We are problem with & (&) char with MagicParser.... If I use demo with
your web-site and put url http://www.mpmaailma.fi/rss/rss.xml everything
seem right but my script drop & char from the line... let's see...

Your web site deme give line...

[LINK] => http://www.mpmaailma.fi/index.php?news=1&news_id=2484

and my script

[LINK] => http://www.mpmaailma.fi/index.php?news=1news_id=2484

I don't understud what is wrong... Would you see my script and
tell what is problem? Thanks.

<?php
header("Content-Type: text/html;charset=ISO-8859-1");
chdir('keskustelut'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';
require_once("include/functions.php");
include("dbstats/logger.php");
require_once("include/MagicParser.php");
function myRecordHandler($record)
  {
        global $db;
    print_r($record);
        $time = $record["PUBDATE"];
        $time = strtotime($time);
        $time = date("H:i",$time);
        $date = $record["PUBDATE"];
        $date = strtotime($date);
        $vuosi=date( "Y", $date );
        $kuukausi=date( "m", $date );
        $paiva=date( "d", $date );
        $databasedatetime="$vuosi-$kuukausi-$paiva $time";
        $hakukanta = $db->query("SELECT * from rssuutiset where linkki ='".$record["LINK"]."'");
        $jee = $db->num_rows($hakukanta);
        if($db->num_rows($hakukanta) == 0){
$db->query("INSERT INTO rssuutiset (uutinenid, lahde, otsikko, alustus, linkki, website, paivamaara,laskuri) VALUES (0,'MP Maailma','".utf8_decode($record["TITLE"])."','".utf8_decode($record["DESCRIPTION"])."','".$record["LINK"]."','http://www.mpmaailma.fi/rss/rss.xml','$databasedatetime',0)");
        }else{
        }
  }
MagicParser_parse("http://www.mpmaailma.fi/rss/rss.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Script output...

Array
(
    [ITEM] =>
    [TITLE] => Kaikki MP 09 -messuista!
    [LINK] => http://www.mpmaailma.fi/index.php?news=1news_id=2484
    [DESCRIPTION] => Lue MP Maailman MP 09 -näyttelyopas ILMAISEKSI!
    [PUBDATE] => Mon, 26 Jan 2009 11:09:00
)

Thanks.

Submitted by support on Mon, 2009-01-26 13:52

Hello,

Yes, this is strange - your code looks fine, so it may be the underlying
PHP xml library is not handling entities correctly.

Could you try perhaps changing the output content type to text/plain using:

header("Content-Type: text/plain;charset=ISO-8859-1");

...just to make sure it is nothing to do with the web server configuration...

Cheers,
David.

Submitted by jopsu on Tue, 2009-01-27 07:10

Hi,

Trying for that but not helps the problem :-(

Submitted by support on Tue, 2009-01-27 09:28

Hello Jopsu,

Could you try a very simply test script:

<?php
  
require_once("include/MagicParser.php");
  
$xml "<test><data>This string contains an &amp; entity!</data></test>";
  function 
myRecordHandler($record)
  {
    print 
$record["DATA"];
  }
  
MagicParser_parse("string://".$xml,"myRecordHandler","xml|TEST/");
?>

...and let me know what is displayed...

Thanks,
David.