FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


parsing xml to html





inphurno
i have a news section that takes data from a xml feed. i am using feed parser called FeedForAll (code can be found here: http://www.feedforall.com/download.htm). i've been having some probs with the em dash, heres an example: SAN FRANCISCOâ€"The presidential candidates...

i've tried using code like this to fix the prob:

Code:
function convert_smart_quotes($string)
{
    $search = array(chr(145),
                    chr(146),
                    chr(147),
                    chr(148),
                    chr(151));

    $replace = array("'",
                     "'",
                     '"',
                     '"',
                     '--');

    return str_replace($search, $replace, $string);
}

$XML = str_replace("—", "&#151#;", $XML); //added extra # so it doesn't get converted
$XML = str_replace("—", "&#151#;", $XML); //added extra # so it doesn't get converted
$XML = convert_smart_quotes($XML);


but this doesn't seem to fix the prob
Sad

any help on this one would be great
rvec
have you tried using the simpleXML functions?
I don't see why you'd need a feedreader for xml functions.
Simulator
this always causes a big problem because when you google it nothing comes up... but the answer is simple, SimpleXML Laughing


http://ie2.php.net/manual/en/function.simplexml-load-file.php
simplexml_load_file if its pulling from another file,

http://ie2.php.net/manual/en/function.simplexml-load-string.php
or simplexml_load_string if you have it imported into your file


You just have to remember its an object not an array... so it's $stringname->parent->child...
inphurno
i get this error when using SimpleXML

simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration

this is my code:

Code:

ini_set('allow_url_fopen', '1');
$XMLfilename = "http://www.feedrinse.com/services/channel/?chanurl=999b6cc7bef39912e08f94dbdb6c2f63";

$xml = simplexml_load_file($XMLfilename);

echo '<pre>';
print_r($xml);
echo '</pre>';
Simulator
yeah.. I should have said that was only for local fies..

If you go:

Code:

$XML = file_get_contents("http://www.feedrinse.com/services/channel/?chanurl=999b6cc7bef39912e08f94dbdb6c2f63");

$xml = simplexml_load_string($XML);

echo '<pre>';
print_r($xml);
echo '</pre>';


That should work
rvec
if it doesn't then it probably uses the same stuff as fopen does and that's disabled on one of the servers. In that case curl is enabled (all frihost servers have either fopen or curl enabled).
Related topics
Webpage Design Programs
What is the difference between HTML and XHTML?
Help making an AJAX messaging system
Feedback please
XML with C++
PHP 4 to PHP 5 Upgrade
[UNIK] Recherche d'aide technique (codeurs, graphistes)
Access Internet On Your Phone Using Pc Internet., Free No Gp
Make some code, get $20 frih$ per contribution.
[php] Php Editor
xml parsing
XML/HTML parsing in PHP
Needed: perl module XML:Parser
Parsing XML Data using Regular Expressions
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.