/    Sign up×
Community /Pin to ProfileBookmark

Parsing an XML document that contains &

I’m trying to parse an XML document that contains an & in the data. When php parses the & it breaks the line into 3 lines instead of one.

Here’s the PHP code:
function opening_element($parser, $element, $attributes){
global $flag1;
if ($element == “image”){
$flag1 = “image”;
}
}
function closing_element($parser, $element){
global $flag1;
if ($element == “image”){
$flag1 = “”;
}
}
function character_data($parser, $data){
global $flag1;
if ($flag1 == “image”){
global $images1;
$images1[] = $data;
}
}

$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, “opening_element”, “closing_element”);
xml_set_character_data_handler($parser, “character_data”);

$document = file(“exp1.xml”);
foreach ($document as $line) {
xml_parse($parser, $line);
}
xml_parser_free($parser);

Here’s the XML:
<image>img/exp/03/B-Architecture &amp; nature…jpg</image>

Here’s the result:
img/exp/03/B-Architecture
&
nature…jpg

It breaks it into 3 lines when I want it in one line.

Any suggestions?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @brohrbach 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.19,
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,
)...