-
-
Save mendesalexandre/cf6f89c6b88eed46ef6dcbd9a9a896b9 to your computer and use it in GitHub Desktop.
Revisions
-
herveguetin revised this gist
Oct 10, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,7 @@ // Create a Zend_Dom_Query object in order to find tags to replace $html = '<dt>Some DT</dt><dd><div>Some DD content</div></dd>'; // Your source HTML $html = utf8_decode($html); $domQuery = new Zend_Dom_Query($html); // Create DOM content for $newItem @@ -59,4 +60,4 @@ // Generate HTML out of complete $newItem $updatedHtml = $newItem->saveHTML(); return utf8_encode($updatedHtml); -
herveguetin revised this gist
Sep 9, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ $newDomElement->setAttribute($attribute, $value); } // Inject all child nodes from $searchedElement into the new DOM element $children = $searchedDomElement->childNodes; foreach($children as $child) { -
herveguetin revised this gist
Sep 9, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,14 +4,16 @@ 'tag' => 'div', // ... <div> tag... 'attributes' => array( // ... with these attributes 'class' => 'some-class', 'id' => 'some_id', 'data-something' => 'some-value' ) ), 'dd' => array( 'tag' => 'div', 'attributes' => array( 'class' => 'some-other-class', 'id' => 'some_other_id', 'data-something' => 'some-other-value' ) ) ); -
herveguetin revised this gist
Sep 9, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,15 @@ 'dt' => array( // <dt> tag is replaced by... 'tag' => 'div', // ... <div> tag... 'attributes' => array( // ... with these attributes 'class' => 'some-class', 'id' => 'some_id' ) ), 'dd' => array( 'tag' => 'div', 'attributes' => array( 'class' => 'some-other-class', 'id' => 'some_other_id' ) ) ); -
herveguetin created this gist
Sep 9, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ <?php $replacedTags = array( 'dt' => array( // <dt> tag is replaced by... 'tag' => 'div', // ... <div> tag... 'attributes' => array( // ... with these attributes 'class' => 'option-title ' . $option->getTitle() . '-option-title' ) ), 'dd' => array( 'tag' => 'div', 'attributes' => array( 'class' => 'option-content ' . $option->getTitle() . '-option-content' ) ) ); // Create a new item that will contain our new DOM elements $newItem = new DOMDocument(); // Create a Zend_Dom_Query object in order to find tags to replace $html = '<dt>Some DT</dt><dd><div>Some DD content</div></dd>'; // Your source HTML $domQuery = new Zend_Dom_Query($html); // Create DOM content for $newItem foreach ($replacedTags as $tag => $config) { // Find DOM elements matching the tag to replace $searchedDomElements = $domQuery->query($tag); foreach ($searchedDomElements as $searchedDomElement) { // Create a new DOM element in $newItem with new tag... $newDomElement = $newItem->createElement($config['tag']); // ... and set updated attributes on this new DOM element foreach($config['attributes'] as $attribute => $value) { $newDomElement->setAttribute($attribute, $value); } // Inject all child nodes from $searchedElement into new DOM element $children = $searchedDomElement->childNodes; foreach($children as $child) { // Create a DOM element in $newItem that is a clone of $child and with all $child's nodes... $newDomElementChild = $newItem->importNode($child, true); // ... and append this DOM element to the new DOM element $newDomElement->appendChild($newDomElementChild); } // Once the new DOM element is ready, append it to the $newItem $newItem->appendChild($newDomElement); } } // Generate HTML out of complete $newItem $updatedHtml = $newItem->saveHTML(); return $updatedHtml;