php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43686 It could be possible to import a string into DomDocument
Submitted: 2007-12-27 02:50 UTC Modified: 2007-12-27 12:40 UTC
From: programatorfreez at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS: Gentoo GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: programatorfreez at gmail dot com
New email:
PHP Version: OS:

 

 [2007-12-27 02:50 UTC] programatorfreez at gmail dot com
Description:
------------
You're missing a very handful feature and it's pretty annoying to make a workaround which cannot perform exactly what I need until PHP is fixed.

Reproduce code:
---------------
This is my crappy workaround for the missing Dom->importString(), however the support in DOM should be made.

        /**
	 * Import a string like something<br /><strong>strong</strong> into the DomDocument
	 *
	 * @param  string     string
	 * @param  DomElement parent
	 * @return DomElement reference to imported node
	 */
	public function importString($string, $parent) {
	    if ($parent === NULL) {
	        throw new Exception('Parent cannot be NULL.');
	    }
	    
	    $tmp = new DomDocument('1.0', 'utf-8');
	    
	    // The div is unwanted here, but loadXml doesn't work without it
	    $tmp->loadXml('<div>' . $string . '</div>');
	    return $this->domImportNode($tmp->firstChild);
	}

Actual result:
--------------
PHP DOM doesn't provide any similar functionaly, although it's needed.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-27 12:40 UTC] rrichards@php.net
Maybe you should read the docs before stating something is broken:
http://www.php.net/manual/en/function.dom-domdocumentfragment-appendxml.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC