/    Sign up×
Community /Pin to ProfileBookmark

Breaking problems down with functions – DOMDocument

I am trying to break parts of my dynamic HTML created with DOMDocument into function. There are certain places where I have multiple blocks of identical code. This sample shows what I am using to achieve this:

[code]$dom_obj- = new DOMDocument(“1.0”, “UFT-8”); // The DOMDocument object for this function.

$helper1 = new DOMDocument(“1.0”, “UFT-8”);
$result_html_string = other_DOMDocument_function($parameter); // saveHTML() output from the another function.
$helper1->loadHtml($result_html_string);

$dom_obj->appendChild($dom_obj->importNode($helper1->documentElement, true));

return $dom_obj->saveHTML();
[/code]

The only thing is this automatically puts a “HTML” and “BODY” tags at the start and end of the code block, which I do not need.

Is there a better way of breaking DOMDocument functions down to smaller functions?

Any thoughts will be appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 05.2022 — FYI: I wrapped your code block in this forum's ... tags, as they work much better than the </> edit option (which is really only suitable for in-line mono-spaced text).
Copy linkTweet thisAlerts:
@NogDogApr 05.2022 — Looks like maybe you could leverage the function suggested in https://stackoverflow.com/questions/2087103/how-to-get-innerhtml-of-domnode/2087136#2087136 to get the inner HTML of the body element, perhaps?
×

Success!

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