/    Sign up×
Community /Pin to ProfileBookmark

Can’t URL decode from DOM

Hi all,

I’ve got this script which converts data from a mysql database to an xml object using the DOM and printing it out. Everything works fine, however some of the text contains ampersands (&) which gets printed as ‘&amp’

here’s the script:

[code=php]
<?
function getdata($type)
{
$mysqHost = “xxx”;
$mysqlUsr = “xxx”;
$mysqlPass = “xxx”;

$conn = mysql_connect($mysqHost,$mysqlUsr,$mysqlPass);

mysql_select_db(“xxx”) ;

$sql = (“SELECT * FROM `$type`;”);
$result = mysql_query($sql);
$doc = new DomDocument(‘1.0’);
$type = $str = str_replace(‘ ‘,”,$type);

$root = $doc->createElement($type.’List’);
$root = $doc->appendChild($root);
while($row = mysql_fetch_assoc($result))
{

$company= $doc->createElement($type);
$company = $root->appendChild($company);
foreach($row as $fieldname => $fieldvalue)
{
if($fieldname !=’id’)
{
$child = $doc->createElement($fieldname);
$child = $company->appendChild($child);
//add data to the new element
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
// $car->appendChild($doc->createElement($fieldname, $fieldvalue)); more efficient way of above

}
}
$str = $doc->saveXML();

print $str;
}

$type = $_REQUEST[‘type’];
getdata($type);

if($conn){ mysql_close($conn); }
?>
[/code]

I’ve tried to decode $fieldValue using html_entity_decode, but it doesn’t work. I really don’t know how to fix this. Any help would be greatly appreciated.

Thanks

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mr_curious spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...