/    Sign up×
Community /Pin to ProfileBookmark

loadXML in different versions

[CODE]
<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’){
$objDOM = new DOMDocument();
$objDOM->loadXML($_POST[‘xml’]);
}
?>
<html>
<body>
<form action=”test.php” method=”post”>
<textarea name=”xml”>
<?php echo($_POST[‘xml’])?>
</textarea>
<input type=”submit”/>
</form>
</body>
</html>

[/CODE]

above is my sample php page where it contains a html form with a textarea names ‘xml’. On form submit PHP is loading the string in the textarea.

adding <R r=”a”/> in textarea and submitting.
xml loads fine with PHP Version 5.3.0

but throws error with PHP Version 5.2.11

[COLOR=”Red”]PHP Warning: DOMDocument::loadXML() [domdocument.loadxml]: AttValue: ” or ‘ expected in Entity, line: 1 in *** on line 4

PHP Warning: DOMDocument::loadXML() [domdocument.loadxml]: attributes construct error in Entity, line: 1 in *** on line 4 PHP

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Couldn’t find end of Start Tag R line 1 in Entity, line: 1 in *** on line 4

PHP Warning: DOMDocument::loadXML() [domdocument.loadxml]: Extra content at the end of the document in Entity, line: 1 in *** on line 4 [/COLOR]

This is a sample page.In actual scenario javascript is building an xml and posting to php.

Something to with encoding. But couldnt get it.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 14.2010 — I would guess it's less likely a PHP version difference than it is a difference in your display_errors and/or error_reporting settings. You can suppress them via the @ operator at the start of your loadXML() line.
Copy linkTweet thisAlerts:
@iusephpauthorFeb 14.2010 — NogDog,

I am new to PHP.. thanks for saving my time....
Copy linkTweet thisAlerts:
@iusephpauthorFeb 14.2010 — echo $objDOM->saveXML();

throwing error....

requirement is to get xml as string.
Copy linkTweet thisAlerts:
@iusephpauthorFeb 14.2010 — its all because of magic_quotes_gpc set to On in server .ini file

adding extra '' slash

How to overwrite this runtime?

tried

ini_set('magic_quotes_gpc', 'off');

ini_set('magic_quotes_runtime', 'off')
Copy linkTweet thisAlerts:
@NogDogFeb 15.2010 — I believe that turning it off in the actual script is too late, as the $_POST/$_GET/$_COOKIE arrays are already populated. You either need to turn it off at the php.ini level or else in a .htaccess file (if running under Apache and allowed to).

Otherwise at runtime you just have to undo the damage via stripslashes() (which you could apply to the entire array via array_walk_recursive if you wanted).
[code=php]
<?php
if (get_magic_quotes_gpc()) {
function noMagic(&$value, $key)
{
$value = stripslashes($value);
}
foreach(array('POST', 'GET', 'COOKIE') as $arr) {
if (!empty(${"_$arr"})) {
array_walk_recursive(${"_$arr"}, 'noMagic');
}
}
}
[/code]
×

Success!

Help @iusephp 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...