php


Can't seem to get PHP appendChild to work correctly when importhing html node


I'm trying to append a node (with sub-nodes) from an imported snippet of html into the body an existing html DOM Document. I've been having a heck of a time trying to get the node to append in the correct place.
Here is my code:
$lastnode = $loaded_file->getElementsByTagName('body')->item(0)->lastChild;
$newnode = $editor_doc->getElementsByTagName('body')->item(0)->firstChild;
$newnode = $loaded_file->importNode($newnode, True);
$lastnode->appendChild($newnode);
$loaded_file is a html file loaded as a DOMDocument using loadHTML.
$editor_doc is the html snippet also loaded as a DOMDocument using loadHTML
The output is the following:
[Entire document of $loaded_file ending with </html>]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>1974
[the correct html snippet]
</p></body></html>
2 problems:
1) The snippet is in the wrong place. I thought it was appending it as a child of the body tag, am I doing something wrong?
2) I have no idea where the extra !DOCTYPE, html, body p and 1974 text are coming from. There is nothing in my code that adds that. Seems to show up when i use appendChild on anything.
What am I doing wrong?
Thanks in advance!
Fixed it. Apparently instead of using loadHTML(readfile($filename)) you have to use loadHTMLfile($filename)) while it seems that everything was loading correctly apparently it wasn't, and i'm not sure why. But once I changed that everything seemed to work correctly.

Related Links

image doesn't show up in production server ( blue question mark )
Radio Buttons within a PHP while loop
php inotify blocking but with timeout
Server returns broken file
Get all texts inside h4, p etc tags and put it inside php gettext
Add Class to knp menu root Element with Twig
.htaccess rewriterule to php page not working
Remove string contained within a specific starting and ending string
search engine using pdo error
SQL LIKE partial match from string
PHP array structure $arr[ ( $arr[$arr] ) ] explaination
Uploading blob into Azure container
Apostrophes and imagettftext()
Laravel 4: setting correct scheme and domain for pagination and form
retrieve/echo updated user account balance with php mysql
Laravel rest path

Categories

HOME
rust
flask
mod-rewrite
gaming
qc
writefile
haproxy
apk
bing-search
dji-sdk
capistrano
google-search-console
angular-meteor
joomla3.2
heap-dump
android-5.1.1-lollipop
web-deployment
tomcat8
word2vec
boomi
psql
home
spyder
kaggle
acl
device
substring
raima
hdmi
clipboard
sap-lumira
fatfs
jsonresult
rust-cargo
quickcheck
ms-media-foundation
counting
custom-keyboard
express-session
identify
strapi
right-click
reverse-dns
music21
cyanogenmod
photoswipe
sonicmq
head.js
ilrepack
hibernate-ogm
cordova-ios
visual-format-language
palindrome
connect-direct
rcharts
nitrousio
xmlbeans
strpos
jeasyui
jeditable
gridbaglayout
gulp-uglify
gwt-syncproxy
stack-smash
google-maps-api-2
dynamics-ax-2012-r2
angular-amd
ocmockito
console.log
tidyr
baseadapter
uno
dnsjava
rubber
inequality
qt5.4
visual-c++-2012
libgcc
accessory
redpitaya
reference-counting
meteor-collections
jomsocial
typesafe-stack
eclim
infinite
non-ascii-characters
void-pointers
eager-loading
rikulo
tfs-sdk
clrprofiler
popup-blocker
n-queens
infopath-2007
servlet-container
anonymous-types
aggregator
uninstaller
yahoo-maps
word-automation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App