/    Sign up×
Community /Pin to ProfileBookmark

Use PHP to get the values of custom internal XML Entities

I have an XML file with the following Document Type Declaration:

“`
<!DOCTYPE Credits SYSTEM “http://www.mrinitialman.com/././DTD-XSD/./mrinitialman.dtd” [
<!ENTITY fa “http://www.furaffinity.net/user/”>
<!ENTITY da “.deviantart.com/”>
<!ENTITY weasyl “https://www.weasyl.com/~”>
<!ENTITY tweet “https://twitter.com/”>
<!ENTITY wiki-en “https://en.wikipedia.org/wiki/”>
<!ENTITY hymnarybio “https://hymnary.org/person/”>
<!ENTITY kerkliedwiki “https://kerkliedwiki.nl/”>
<!ENTITY wiki-nl “https://nl.wikipedia.org/wiki/”>
]>
“`

My PHP is simply ignoring all entity references; for example instead of seeing the attribute `url=”&wiki-en;Anne_Steele”` and sending along “https://en.wikipedia.org/wiki/Anne_Steele“, the code simply sends along “Anne_Steele”, which causes my hyperlinks to not work.

So, I’d like to try a workaround in which I have PHP read all the Entities and get their text values, and go from there.

The problem is, I’m not getting anything.

For example: should I try the following:

“`PHP
$entityarray=array();
$xml = new DOMDocument();
$xml->LoadXML(xmlfile.xml);
$entities = $xml->doctype->entities;
for($entity_num = 0; $entity_num < $entities->length; $entity_num++){
$entity = $entities->item($entity_num);
$entity_name = $entity->nodeName;
$entityarray[$entity_name] = $xml->SaveXML($entity);
}
“`

I get an associated array of the _whole_ Entity (for example, “`<!ENTITY wiki-en “https://en.wikipedia.org/wiki/”>“`)

If, however, I try this:

“`PHP
for($entity_num = 0; $entity_num < $entities->length; $entity_num++){
$entity = $entities->item($entity_num);
$entity_name = $entity->nodeName;
$entityarray[$entity_name] = $entity->nodeValue;
}
“`

or

“`PHP
for($entity_num = 0; $entity_num < $entities->length; $entity_num++){
$entity = $entities->item($entity_num);
$entity_name = $entity->nodeName;
$entityarray[$entity_name] = $entity->textContent;
}
“`

I get an associated array of empty strings. Do I need to trim the entity code down to what I want? Is there something else I should do? Or am I just wasting my time struggling with Entity references?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@satyashaktiJun 14.2022 — thanks for sharing your information with us

Satya Shakti Foundation are private agencies in Delhi. Satya shakti foundation work to promote social or political change and play a critical role in developing society, A Non-Governmental Organization (NGO)is improving the welfare of the disadvantaged, or representing a corporate agenda and supports people their rights.

https://www.satyashaktifoundation.org/
×

Success!

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