---
description: >-
  https://hotexamples.com/examples/-/domDocument/getElementsByTagname/php-domdocument-getelementsbytagname-method-examples.html
---

# PHP domDocument::getElementsByTagname Examples



**PHP domDocument::getElementsByTagname - 11 examples found**. These are the top rated real world PHP examples of **domDocument::getElementsByTagname** extracted from open source projects. You can rate examples to help us improve the quality of examples.Programming Language: PHPClass/Type: [domDocument](https://hotexamples.com/examples/-/domDocument/-/php-domdocument-class-examples.html)Method/Function: getElementsByTagnameExamples at hotexamples.com: 11[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)FREQUENTLY USED METHODS[loadHTML (30)](https://hotexamples.com/examples/-/domDocument/loadHTML/php-domdocument-loadhtml-method-examples.html)[load (30)](https://hotexamples.com/examples/-/domDocument/load/php-domdocument-load-method-examples.html)[loadXML (30)](https://hotexamples.com/examples/-/domDocument/loadXML/php-domdocument-loadxml-method-examples.html)[getElementsByTagName (30)](https://hotexamples.com/examples/-/domDocument/getElementsByTagName/php-domdocument-getelementsbytagname-method-examples.html)[createElement (24)](https://hotexamples.com/examples/-/domDocument/createElement/php-domdocument-createelement-method-examples.html)[saveXML (18)](https://hotexamples.com/examples/-/domDocument/saveXML/php-domdocument-savexml-method-examples.html)[appendChild (15)](https://hotexamples.com/examples/-/domDocument/appendChild/php-domdocument-appendchild-method-examples.html)[getElementById (12)](https://hotexamples.com/examples/-/domDocument/getElementById/php-domdocument-getelementbyid-method-examples.html)[getElementsByTagname (11)](https://hotexamples.com/examples/-/domDocument/getElementsByTagname/php-domdocument-getelementsbytagname-method-examples.html)[save (11)](https://hotexamples.com/examples/-/domDocument/save/php-domdocument-save-method-examples.html)[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)[![Ezoic](https://go.ezoic.net/utilcave_com/img/ezoic.png)](https://www.ezoic.com/what-is-ezoic/)report this adFREQUENTLY USED METHODS[loadHTMLFile (9)](https://hotexamples.com/examples/-/domDocument/loadHTMLFile/php-domdocument-loadhtmlfile-method-examples.html)[saveHTML (7)](https://hotexamples.com/examples/-/domDocument/saveHTML/php-domdocument-savehtml-method-examples.html)[createTextNode (6)](https://hotexamples.com/examples/-/domDocument/createTextNode/php-domdocument-createtextnode-method-examples.html)[loadxml (4)](https://hotexamples.com/examples/-/domDocument/loadxml/php-domdocument-loadxml-method-examples.html)[removeChild (3)](https://hotexamples.com/examples/-/domDocument/removeChild/php-domdocument-removechild-method-examples.html)[createElementNS (3)](https://hotexamples.com/examples/-/domDocument/createElementNS/php-domdocument-createelementns-method-examples.html)[createAttribute (3)](https://hotexamples.com/examples/-/domDocument/createAttribute/php-domdocument-createattribute-method-examples.html)[loadHtml (2)](https://hotexamples.com/examples/-/domDocument/loadHtml/php-domdocument-loadhtml-method-examples.html)[validate (2)](https://hotexamples.com/examples/-/domDocument/validate/php-domdocument-validate-method-examples.html)[importNode (2)](https://hotexamples.com/examples/-/domDocument/importNode/php-domdocument-importnode-method-examples.html)[getElementsByTagNameNS (2)](https://hotexamples.com/examples/-/domDocument/getElementsByTagNameNS/php-domdocument-getelementsbytagnamens-method-examples.html)[\_\_construct (2)](https://hotexamples.com/examples/-/domDocument/__construct/php-domdocument-__construct-method-examples.html)[createCDATASection (2)](https://hotexamples.com/examples/-/domDocument/createCDATASection/php-domdocument-createcdatasection-method-examples.html)[getElementsbyTagName (1)](https://hotexamples.com/examples/-/domDocument/getElementsbyTagName/php-domdocument-getelementsbytagname-method-examples.html)[loadXml (1)](https://hotexamples.com/examples/-/domDocument/loadXml/php-domdocument-loadxml-method-examples.html)[loadhtml (1)](https://hotexamples.com/examples/-/domDocument/loadhtml/php-domdocument-loadhtml-method-examples.html)[getElementsBytagName (1)](https://hotexamples.com/examples/-/domDocument/getElementsBytagName/php-domdocument-getelementsbytagname-method-examples.html)[relaxNGValidate (1)](https://hotexamples.com/examples/-/domDocument/relaxNGValidate/php-domdocument-relaxngvalidate-method-examples.html)[createComment (1)](https://hotexamples.com/examples/-/domDocument/createComment/php-domdocument-createcomment-method-examples.html)[createCdataSection (1)](https://hotexamples.com/examples/-/domDocument/createCdataSection/php-domdocument-createcdatasection-method-examples.html)FREQUENTLY USED METHODS[getElementsByTagNameNS (2)](https://hotexamples.com/examples/-/domDocument/getElementsByTagNameNS/php-domdocument-getelementsbytagnamens-method-examples.html)[\_\_construct (2)](https://hotexamples.com/examples/-/domDocument/__construct/php-domdocument-__construct-method-examples.html)[createCDATASection (2)](https://hotexamples.com/examples/-/domDocument/createCDATASection/php-domdocument-createcdatasection-method-examples.html)[getElementsbyTagName (1)](https://hotexamples.com/examples/-/domDocument/getElementsbyTagName/php-domdocument-getelementsbytagname-method-examples.html)[loadXml (1)](https://hotexamples.com/examples/-/domDocument/loadXml/php-domdocument-loadxml-method-examples.html)[loadhtml (1)](https://hotexamples.com/examples/-/domDocument/loadhtml/php-domdocument-loadhtml-method-examples.html)[getElementsBytagName (1)](https://hotexamples.com/examples/-/domDocument/getElementsBytagName/php-domdocument-getelementsbytagname-method-examples.html)[relaxNGValidate (1)](https://hotexamples.com/examples/-/domDocument/relaxNGValidate/php-domdocument-relaxngvalidate-method-examples.html)[createComment (1)](https://hotexamples.com/examples/-/domDocument/createComment/php-domdocument-createcomment-method-examples.html)[createCdataSection (1)](https://hotexamples.com/examples/-/domDocument/createCdataSection/php-domdocument-createcdatasection-method-examples.html)[savexml (1)](https://hotexamples.com/examples/-/domDocument/savexml/php-domdocument-savexml-method-examples.html)[schemaValidate (1)](https://hotexamples.com/examples/-/domDocument/schemaValidate/php-domdocument-schemavalidate-method-examples.html)[CreateElement (1)](https://hotexamples.com/examples/-/domDocument/CreateElement/php-domdocument-createelement-method-examples.html)RELATED IN LANGS[CropAnchorPosition (C#)](https://csharp.hotexamples.com/examples/-/CropAnchorPosition/-/php-cropanchorposition-class-examples.html)[HeaderInfo (C#)](https://csharp.hotexamples.com/examples/WindowsFormsApplication1/HeaderInfo/-/php-headerinfo-class-examples.html)[old\_decode\_dev (C++)](https://cpp.hotexamples.com/examples/-/-/old_decode_dev/cpp-old_decode_dev-function-examples.html)[C\_SUB (C++)](https://cpp.hotexamples.com/examples/-/-/C_SUB/cpp-c_sub-function-examples.html)[FlagSet (Go)](https://golang.hotexamples.com/examples/github.com.emerald-ci.test-runner.godeps._workspace.src.github.com.docker.docker.pkg.mflag/FlagSet/-/golang-flagset-class-examples.html)[NewPersp (Go)](https://golang.hotexamples.com/examples/vu.math.lin/-/NewPersp/golang-newpersp-function-examples.html)[Calendar (Java)](https://java.hotexamples.com/examples/org.apache.poi.xssf.usermodel/Calendar/-/java-calendar-class-examples.html)[WTransform (Java)](https://java.hotexamples.com/examples/javax.servlet.http/WTransform/-/java-wtransform-class-examples.html)[is\_larger\_than (Python)](https://python.hotexamples.com/examples/thelma.tools.utils.base/-/is_larger_than/python-is_larger_than-function-examples.html)[valid\_user\_path (Python)](https://python.hotexamples.com/examples/shared.validstring/-/valid_user_path/python-valid_user_path-function-examples.html)FREQUENTLY USED METHODS[savexml (1)](https://hotexamples.com/examples/-/domDocument/savexml/php-domdocument-savexml-method-examples.html)[schemaValidate (1)](https://hotexamples.com/examples/-/domDocument/schemaValidate/php-domdocument-schemavalidate-method-examples.html)[CreateElement (1)](https://hotexamples.com/examples/-/domDocument/CreateElement/php-domdocument-createelement-method-examples.html)RELATED[printforUS](https://hotexamples.com/examples/-/-/printforUS/php-printforus-function-examples.html)[Tournament](https://hotexamples.com/examples/app/Tournament/-/php-tournament-class-examples.html)[AuthorExplicitSequence](https://hotexamples.com/examples/-/AuthorExplicitSequence/-/php-authorexplicitsequence-class-examples.html)[databaseConnect](https://hotexamples.com/examples/-/-/databaseConnect/php-databaseconnect-function-examples.html)[date\_db](https://hotexamples.com/examples/-/-/date_db/php-date_db-function-examples.html)[room\_link](https://hotexamples.com/examples/-/-/room_link/php-room_link-function-examples.html)[BaseLog](https://hotexamples.com/examples/cake.log.engine/BaseLog/-/php-baselog-class-examples.html)[InvalidXmlException](https://hotexamples.com/examples/-/InvalidXmlException/-/php-invalidxmlexception-class-examples.html)[evaluation\_edit\_use\_template\_form](https://hotexamples.com/examples/-/evaluation_edit_use_template_form/-/php-evaluation_edit_use_template_form-class-examples.html)[DpleFeatureLinksBase](https://hotexamples.com/examples/-/DpleFeatureLinksBase/-/php-dplefeaturelinksbase-class-examples.html)Google BookmarkFacebookTwitterPrintEmailMore1EXAMPLE #10   Show fileFile: [multiselect.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fkenners%2Fuamuzi-bora%2Fblob%2Fmaster%2Fwww%2Fapp%2Fviews%2Fmultiselect.php) Project: [kenners/uamuzi-bora](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fkenners%2Fuamuzi-bora)

```
 /**
  * Extract selected items array from html multiselect tag
  *
  * @param array Html multiselect tag
  * @return array Selected items array
  */
 private function getSelectedItems($html)
 {
     $dom = new domDocument();
     $dom->loadHTML($html);
     $dom->preserveWhiteSpace = false;
     $options = $dom->getElementsByTagname('option');
     $items = array();
     foreach ($options as $option) {
         if ($option->hasAttribute('selected')) {
             $items[] = $option->nodeValue;
         }
     }
     return $items;
 }
```

EXAMPLE #20   Show fileFile: [index\_template.inc.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fslims%2Fs3st15_matoa%2Fblob%2Fmaster%2Ftemplate%2Findex_template.inc.php) Project: [slims/s3st15\_matoa](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fslims%2Fs3st15_matoa)

```
/**
 *
 * from http://www.phpro.org/examples/Get-Text-Between-Tags.html
 * 
 * @get text between tags
 * @param string $tag The tag name
 * @param string $html The XML or XHTML string
 * @param int $strict Whether to use strict mode
 * @return array
 *
 */
function getTextBetweenTags($tag, $html, $strict = 0)
{
    $dom = new domDocument();
    if ($strict == 1) {
        $dom->loadXML($html);
    } else {
        $dom->loadHTML($html);
    }
    $dom->preserveWhiteSpace = false;
    $content = $dom->getElementsByTagname($tag);
    $out = array();
    foreach ($content as $item) {
        $out[] = $item->nodeValue;
    }
    return $out;
}
```

EXAMPLE #30   Show fileFile: [BaseController.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnitin-prodigi%2Fmesa%2Fblob%2Fmaster%2Fapp%2FHttp%2FBaseController.php) Project: [nitin-prodigi/mesa](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnitin-prodigi%2Fmesa)

```
 protected function formatCode($article)
 {
     echo $cont = $article['content'];
     $dom = new \domDocument();
     $dom->loadHTML($cont);
     $dom->preserveWhiteSpace = false;
     $codeelement = $dom->getElementsByTagname('code');
     $i = $codeelement->length - 1;
     while ($i > -1) {
         $element = $codeelement->item($i);
         echo $element->nodeValue;
         echo "<br />";
         echo $newelement = htmlentities($element->nodeValue);
         exit;
         $element->parentNode->replaceChild($newelement, $element);
         $i--;
     }
     exit;
     return $article;
 }
```

EXAMPLE #40   Show fileFile: [podskazki.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Flaiello%2Fcartonbank%2Fblob%2Fmaster%2Fales%2Fpodskazki.php) Project: [laiello/cartonbank](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Flaiello%2Fcartonbank)

```
function getTextBetweenTags($tag, $html, $strict = 0)
{
    /*** a new dom object ***/
    //$dom = new domDocument;
    $dom = new domDocument('1.0', 'UTF-8');
    /*** load the html into the object ***/
    $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
    @$dom->loadHTML($html);
    /*** discard white space ***/
    $dom->preserveWhiteSpace = false;
    /*** the tag by its tag name ***/
    $content = $dom->getElementsByTagname($tag);
    /*** the array to return ***/
    ////$out = array();
    $out = "";
    foreach ($content as $item) {
        /*** add node value to the out array ***/
        $out .= "\"" . $item->nodeValue . "\", ";
    }
    /*** return the results ***/
    return $out;
}
```

EXAMPLE #50   Show fileFile: [functions.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fadww%2Fblockbot-games%2Fblob%2Fmaster%2Ffunctions.php) Project: [adww/blockbot-games](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fadww%2Fblockbot-games)

```
/**
 *
 * @get text between tags
 *
 * @param string $tag The tag name
 *
 * @param string $html The XML or XHTML string
 *
 * @param int $strict Whether to use strict mode
 *
 * @return array
 *
 */
function getTextBetweenTags($tag, $html, $strict = 0)
{
    /*** a new dom object ***/
    $dom = new domDocument();
    /*** load the html into the object ***/
    if ($strict == 1) {
        $dom->loadXML($html);
    } else {
        $dom->loadHTML($html);
    }
    /*** discard white space ***/
    $dom->preserveWhiteSpace = false;
    /*** the tag by its tag name ***/
    $content = $dom->getElementsByTagname($tag);
    /*** the array to return ***/
    $out = array();
    foreach ($content as $item) {
        /*** add node value to the out array ***/
        $out[] = $item->nodeValue;
    }
    /*** return the results ***/
    return $out;
}
```

EXAMPLE #60   Show fileFile: [dom1.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcefalo19%2Fphp-src%2Fblob%2Fmaster%2Fext%2Fdom%2Fdom1.php) Project: [cefalo19/php-src](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcefalo19%2Fphp-src)

```
echo "--------- Remove Attribute Node\n";
$attr = $rootnode->removeAttribute("src");
print "Removed " . $attr . " attributes.\n";
echo "--------- attributes of rootnode\n";
$attrs = $rootnode->attributes;
print_node_list($attrs);
echo "--------- children of an attribute\n";
$children = $attrs->item(0)->childNodes;
print_node_list($children);
echo "--------- Add child to root\n";
$myelement = new domElement("Silly", "Symphony");
$newchild = $rootnode->appendChild($myelement);
print_node($newchild);
print $dom->saveXML();
print "\n";
echo "--------- Find element by tagname\n";
echo "    Using dom\n";
$children = $dom->getElementsByTagname("Silly");
print_node_list($children);
echo "    Using elem\n";
$children = $rootnode->getElementsByTagName("Silly");
print_node_list($children);
echo "--------- Unlink Node\n";
print_node($children->item(0));
$rootnode->removeChild($children->item(0));
print_node_list($rootnode->childNodes);
print $dom->savexml();
echo "--------- Find element by id\n";
print "Not implemented\n";
echo "--------- Check various node_name return values\n";
print "Not needed\n";
```

EXAMPLE #70   Show fileFile: [elements.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fb0123498765%2Ffithealthyandwealthy%2Fblob%2Fmaster%2Fwp-content%2Fthemes%2Funcode%2Felements.php) Project: [b0123498765/fithealthyandwealthy](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fb0123498765%2Ffithealthyandwealthy)

```
/**
 * Build background HTML
 */
function uncode_get_back_html($background = array(), $overlay_color = '', $overlay_color_alpha = '', $overlay_pattern = '', $type)
{
    global $front_background_colors;
    $back_color = $back_url = $back_repeat = $back_position = $back_attachment = $back_size = $background_mime = $background_url = $header_background_video = $header_background_selfvideo = $header_overlay_html = $header_overlay_style = $header_overlay_pattern_style = $back_mime_css = $back_html = $content_html = $carousel_html = $overlay_html = '';
    $poster_id = $is_carousel = $content_only_text = false;
    if (!empty($background['background-image'])) {
        $media_ids = explode(',', $background['background-image']);
        if (count($media_ids) === 1) {
            $back_attributes = uncode_get_media_info($background['background-image']);
            if (isset($back_attributes->post_mime_type)) {
                $background_mime = $back_attributes->post_mime_type;
            }
            $back_repeat = isset($background['background-repeat']) && $background['background-repeat'] !== '' ? 'background-repeat: ' . $background['background-repeat'] . ';' : '';
            $back_position = isset($background['background-position']) && $background['background-position'] !== '' ? 'background-position: ' . $background['background-position'] . ';' : '';
            $back_attachment = isset($background['background-attachment']) && $background['background-attachment'] !== '' ? 'background-attachment: ' . $background['background-attachment'] . ';' : '';
            $back_size = isset($background['background-size']) && $background['background-size'] !== '' ? 'background-size: ' . $background['background-size'] . ';' : '';
            if (strpos($background_mime, 'video/') !== false || $background_mime === 'oembed/vimeo' || $background_mime === 'oembed/youtube') {
                if (wp_is_mobile()) {
                    $background_mime = 'mobile_no_video';
                }
            }
            if (strpos($background_mime, 'image/') !== false) {
                $back_metavalues = unserialize($back_attributes->metadata);
                $image_orig_w = $back_metavalues['width'];
                $image_orig_h = $back_metavalues['height'];
                $resized_back = uncode_resize_image($back_attributes->guid, $back_attributes->path, $image_orig_w, $image_orig_h, 12, '', false);
                $background_url = $resized_back['url'];
                $back_url = $background_url != '' ? 'background-image: url(' . $background_url . ');' : '';
            } else {
                if (strpos($background_mime, 'video/') !== false) {
                    $videos = array();
                    $exloded_url = explode(".", strtolower($back_attributes->guid));
                    $ext = end($exloded_url);
                    $videos[(string) $ext] = $back_attributes->guid;
                    $alt_videos = get_post_meta($background['background-image'], "_uncode_video_alternative", true);
                    if (!empty($alt_videos)) {
                        foreach ($alt_videos as $key => $value) {
                            $exloded_url = explode(".", strtolower($value));
                            $ext = end($exloded_url);
                            $videos[(string) $ext] = $value;
                        }
                    } else {
                        $videos = array('src' => '"' . $back_attributes->guid . '"');
                    }
                    $video_src = '';
                    foreach ($videos as $key => $value) {
                        $video_src .= ' ' . $key . '=' . $value;
                    }
                    $back_mime_css = ' self-video uncode-video-container';
                    add_filter("wp_video_shortcode_class", "uncode_back_video_class", 10, 2);
                    $header_background_selfvideo = apply_filters('the_content', '[video' . $video_src . ' loop="y"]');
                    $header_background_selfvideo = str_replace('controls="controls"', '', $header_background_selfvideo);
                    remove_filter("wp_video_shortcode_class", "uncode_back_video_class");
                } else {
                    switch ($background_mime) {
                        case 'oembed/flickr':
                        case 'oembed/Imgur':
                        case 'oembed/photobucket':
                            $back_oembed = wp_oembed_get($back_attributes->guid);
                            preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src);
                            $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : '';
                            if ($background_mime === 'oembed/flickr') {
                                $back_url = str_replace('_n.', '_b.', $back_url);
                            }
                            $background_url = $back_url;
                            $background_mime = 'image';
                            break;
                        case 'oembed/instagram':
                            $url = 'http://api.instagram.com/oembed?url=' . $back_attributes->guid;
                            $json = wp_remote_fopen($url);
                            $json_data = json_decode($json, true);
                            $background_url = $back_url = $json_data['thumbnail_url'];
                            $back_url = isset($json_data['thumbnail_url']) ? 'background-image: url(' . esc_url($json_data['thumbnail_url']) . ');' : '';
                            $background_mime = 'image';
                            break;
                        case 'oembed/vimeo':
                        case 'oembed/youtube':
                            $back_metavalues = unserialize($back_attributes->metadata);
                            $video_orig_w = $back_metavalues['width'];
                            $video_orig_h = $back_metavalues['height'];
                            $video_ratio = $video_orig_h === 0 ? 1.777 : $video_orig_w / $video_orig_h;
                            $header_background_video = ' data-ratio="' . $video_ratio . '" data-provider="' . ($background_mime === 'oembed/vimeo' ? 'vimeo' : 'youtube') . '" data-video="' . $back_attributes->guid . '" data-id="' . rand(10000, 99999) . '"';
                            $back_mime_css = ' video uncode-video-container';
                            break;
                        case 'oembed/soundcloud':
                            $url = $back_attributes->guid;
                            $accent_color = $front_background_colors['accent'];
                            $accent_color = str_replace('#', '', $accent_color);
                            $getValues = wp_remote_fopen('http://soundcloud.com/oembed?format=js&url=' . $url . '&iframe=true');
                            $decodeiFrame = substr($getValues, 1, -2);
                            $decodeiFrame = json_decode($decodeiFrame);
                            preg_match('/src="([^"]+)"/', $decodeiFrame->html, $iframe_src);
                            $iframe_url = str_replace('visual=true', 'visual=false', $iframe_src[1]);
                            $content_html = '<iframe width="100%" scrolling="no" frameborder="no" src="' . $iframe_url . '&color=' . $accent_color . '&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>';
                            break;
                        case 'oembed/twitter':
                            $url = 'https://api.twitter.com/1/statuses/oembed.json?id=' . basename($back_attributes->guid);
                            $json = wp_remote_fopen($url);
                            $json_data = json_decode($json, true);
                            $id = basename($json_data['url']);
                            $html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $json_data['html']);
                            $html = str_replace("&mdash; ", '', $html);
                            $dom = new domDocument();
                            $dom->loadHTML($html);
                            $dom->preserveWhiteSpace = false;
                            $twitter_content = $dom->getElementsByTagname('blockquote');
                            $twitter_blockquote = '';
                            $twitter_footer = '';
                            foreach ($twitter_content as $item) {
                                $twitter_content_inner = $item->getElementsByTagname('p');
                                foreach ($twitter_content_inner as $item_inner) {
                                    foreach ($item_inner->childNodes as $child) {
                                        $twitter_blockquote .= $child->ownerDocument->saveXML($child);
                                    }
                                    $item_inner->parentNode->removeChild($item_inner);
                                }
                                foreach ($item->childNodes as $child) {
                                    $twitter_footer .= $child->ownerDocument->saveXML($child);
                                }
                                $item->parentNode->removeChild($item);
                            }
                            $content_html = '<div class="twitter-item">
																<div class="twitter-item-data">
																	<blockquote class="tweet-text pullquote">
																		<p>' . $twitter_blockquote . '</p>';
                            $content_html .= '<p class="twitter-footer"><small>' . $twitter_footer . '</small></p>';
                            $content_html .= '</blockquote>
																</div>
															</div>';
                            $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true);
                            if ($poster !== '') {
                                $poster_attributes = uncode_get_media_info($poster);
                                $media_metavalues = unserialize($poster_attributes->metadata);
                                $image_orig_w = $media_metavalues['width'];
                                $image_orig_h = $media_metavalues['height'];
                                $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false);
                                $poster_url = $resized_image['url'];
                                if (isset($poster_attributes->post_mime_type)) {
                                    $background_mime = $poster_attributes->post_mime_type;
                                }
                                if (strpos($background_mime, 'image/') !== false) {
                                    $background_url = $poster_url;
                                    $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : '';
                                } else {
                                    $back_oembed = wp_oembed_get($poster_attributes->guid);
                                    preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src);
                                    $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : '';
                                }
                                $poster_id = $background['background-image'];
                            }
                            $content_only_text = true;
                            break;
                        case 'oembed/html':
                            if (isset($back_attributes->post_excerpt) && $back_attributes->post_excerpt !== '') {
                                $author = '<p><small>' . $back_attributes->post_excerpt . '</small></p>';
                            } else {
                                $author = '';
                            }
                            $content_html = '<blockquote class="pullquote"><p>' . $back_attributes->post_content . '</p>' . $author . '</blockquote>';
                            $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true);
                            if ($poster !== '') {
                                $poster_attributes = uncode_get_media_info($poster);
                                $media_metavalues = unserialize($poster_attributes->metadata);
                                $image_orig_w = $media_metavalues['width'];
                                $image_orig_h = $media_metavalues['height'];
                                $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false);
                                $poster_url = $resized_image['url'];
                                if (isset($poster_attributes->post_mime_type)) {
                                    $background_mime = $poster_attributes->post_mime_type;
                                }
                                if (strpos($background_mime, 'image/') !== false) {
                                    $background_url = $poster_url;
                                    $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : '';
                                } else {
                                    $back_oembed = wp_oembed_get($poster_attributes->guid);
                                    preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src);
                                    $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : '';
                                }
                                $poster_id = $background['background-image'];
                            }
                            $content_only_text = true;
                            break;
                        default:
                            if (strpos($background_mime, 'audio/') !== false) {
                                $content_html = apply_filters('the_content', '[audio src="' . $back_attributes->guid . '"]');
                            } else {
                                if ($background_mime === 'oembed/spotify') {
                                    $content_html = wp_oembed_get($back_attributes->guid);
                                }
                            }
                            $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true);
                            if ($poster !== '') {
                                $poster_attributes = uncode_get_media_info($poster);
                                $media_metavalues = unserialize($poster_attributes->metadata);
                                $image_orig_w = $media_metavalues['width'];
                                $image_orig_h = $media_metavalues['height'];
                                $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false);
                                $poster_url = $resized_image['url'];
                                if (isset($poster_attributes->post_mime_type)) {
                                    $background_mime = $poster_attributes->post_mime_type;
                                }
                                if (strpos($background_mime, 'image/') !== false) {
                                    $background_url = $poster_url;
                                    $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : '';
                                } else {
                                    $back_oembed = wp_oembed_get($poster_attributes->guid);
                                    preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src);
                                    $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : '';
                                }
                                $poster_id = $background['background-image'];
                            }
                            break;
                    }
                }
            }
        } else {
            $carousel_html = do_shortcode('[vc_gallery el_id="gallery-' . rand() . '" medias="' . $background['background-image'] . '" type="carousel" style_preset="metro" single_padding="0" carousel_fluid="yes" carousel_lg="1" carousel_md="1" carousel_sm="1" gutter_size="0" media_items="media" carousel_interval="0" carousel_dots="yes" carousel_autoh="no" carousel_type="fade" carousel_nav="no" carousel_dots_inside="yes" single_text="overlay" single_border="yes" single_width="12" single_height="12" single_text_visible="no" single_text_anim="no" single_overlay_visible="no" single_overlay_anim="no" single_image_anim="no"]');
            $is_carousel = true;
        }
    }
    if (isset($background['background-color']) && $background['background-color'] !== '') {
        $back_color = ' style-' . $background['background-color'] . '-bg';
    }
    if ($overlay_color !== '') {
        $overlay_color = ' style-' . $overlay_color . '-bg';
    }
    if ($overlay_color_alpha !== '' && $overlay_color !== '') {
        $overlay_color_alpha = ' style="opacity: ' . $overlay_color_alpha / 100 . ';"';
    } else {
        $overlay_color_alpha = '';
    }
    if (!empty($overlay_pattern)) {
        $overlay_pattern = ' uncode-' . $overlay_pattern;
    }
    if (!empty($overlay_pattern) && $overlay_pattern !== '') {
        $header_overlay_pattern_style = '<div class="header-bg-overlay-inner' . $overlay_pattern . '"' . $overlay_color_alpha . '></div>';
    }
    if (!empty($overlay_color) && $overlay_color !== '') {
        $header_overlay_style = '<div class="header-bg-overlay-inner' . $overlay_color . '"' . $overlay_color_alpha . '></div>';
    }
    if ($header_overlay_style !== '' || $header_overlay_pattern_style !== '') {
        $header_overlay_html = '<div class="header-bg-overlay">' . $header_overlay_style . $header_overlay_pattern_style . ' </div>';
    }
    $back_image = $back_url != '' || $back_repeat != '' || $back_position != '' || $back_attachment != '' || $back_size != '' ? ' style="' . $back_url . $back_repeat . $back_position . $back_attachment . $back_size . '"' : '';
    if ($overlay_color !== '') {
        $overlay_html = '<div class="block-bg-overlay' . $overlay_color . '"' . $overlay_color_alpha . '></div>';
    }
    if ($type === 'row') {
        $back_html = '<div class="row-background background-element"' . ($back_mime_css === '' && $header_background_video === '' && $back_image === '' && $header_background_selfvideo === '' && $back_html === '' ? ' style="opacity: 1;"' : '') . '>
										<div class="background-wrapper">
											<div class="background-inner' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div>
											' . $overlay_html . '
										</div>
									</div>';
    } else {
        if ($type === 'column') {
            $back_html = '<div class="column-background background-element"' . ($back_mime_css === '' && $header_background_video === '' && $back_image === '' && $header_background_selfvideo === '' && $back_html === '' ? ' style="opacity: 1;"' : '') . '>
										<div class="background-wrapper">
											<div class="background-inner' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div>
											' . $overlay_html . '
										</div>
									</div>';
        } else {
            if ($type === 'div') {
                if ($header_background_video !== '' || $back_image !== '' || $header_background_selfvideo !== '' || $back_html !== '') {
                    $back_html = '<div class="main-background background-element">
											<div class="' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div>
										</div>';
                }
            } else {
                if ($overlay_html !== '' || $header_background_video !== '' || $back_image !== '' || $header_background_selfvideo !== '' || $carousel_html !== '') {
                    $back_html = '<div class="header-bg-wrapper">
										<div class="header-bg' . $back_mime_css . ($carousel_html !== '' ? ' header-carousel-wrapper' : '') . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $carousel_html . '</div>
										' . $overlay_html . '
									</div>';
                }
            }
        }
    }
    return array('back_color' => $back_color, 'back_html' => $back_html, 'content_html' => $content_html, 'content_only_text' => $content_only_text, 'back_url' => $background_url, 'poster_id' => $poster_id, 'is_carousel' => $is_carousel, 'mime' => $background_mime);
}
```

EXAMPLE #80   Show fileFile: [save\_content.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnetconstructor%2Fforkcms%2Fblob%2Fmaster%2Fdefault_www%2Fbackend%2Fmodules%2Fmailmotor%2Fsave_content.php) Project: [netconstructor/forkcms](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnetconstructor%2Fforkcms)

```
 /**
  * Returns the text between 2 tags
  *
  * @return	array
  * @param	string $tag					The tag.
  * @param	string $html				The HTML to search in.
  * @param	bool[optional] $strict		Use strictmode?
  */
 private function getTextBetweenTags($tag, $html, $strict = false)
 {
     // new dom document
     $dom = new domDocument();
     // load HTML
     $strict == true ? $dom->loadXML($html) : $dom->loadHTML($html);
     // discard whitespace
     $dom->preserveWhiteSpace = false;
     // the array with results
     $results = array();
     // fetch the tag by name
     $content = $dom->getElementsByTagname($tag);
     // loop the content
     foreach ($content as $item) {
         // add node value to results
         $results[] = $item->nodeValue;
     }
     // return the results
     return $results;
 }
```

EXAMPLE #90   Show fileFile: [helpers.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fb0123498765%2Ffithealthyandwealthy%2Fblob%2Fmaster%2Fwp-content%2Fthemes%2Funcode%2Fcore%2Fhelpers.php) Project: [b0123498765/fithealthyandwealthy](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fb0123498765%2Ffithealthyandwealthy)

```
/**
 * oEmbed helper
 * @param  [int] $id
 * @param  [string] $url
 * @return [array]
 */
function uncode_get_oembed($id, $url, $mime, $with_poster = false, $excerpt = null, $html = null, $lighbox_code = false)
{
    global $front_background_colors;
    $object_class = $poster = $poster_id = '';
    $oembed_size = uncode_get_dummy_size($id);
    $media_type = 'other';
    if ($with_poster) {
        $poster = get_post_meta($id, "_uncode_poster_image", true);
        $poster_id = $poster;
    }
    switch ($mime) {
        case 'oembed/flickr':
        case 'oembed/Imgur':
        case 'oembed/photobucket':
            $media_type = 'image';
            $media_oembed = wp_oembed_get($url);
            preg_match_all('/src="([^"]*)"/i', $media_oembed, $img_src);
            $media_oembed = isset($img_src[1][0]) ? str_replace('"', '', $img_src[1][0]) : '';
            if ($mime === 'oembed/flickr') {
                $media_oembed = str_replace('_n.', '_b.', $media_oembed);
            }
            break;
        case 'oembed/instagram':
            $media_type = 'image';
            $url = 'http://api.instagram.com/oembed?url=' . $url;
            $json = wp_remote_fopen($url);
            $json_data = json_decode($json, true);
            $media_oembed = $json_data['thumbnail_url'];
            $oembed_size['width'] = $oembed_size['height'] = 640;
            break;
        case 'oembed/youtube':
            if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                $get_url = parse_url($url);
                if (isset($get_url['query'])) {
                    $get_id = explode('=', $get_url['query']);
                    $src_id = $get_id[1];
                } else {
                    $src_id = basename($url);
                }
                $media_oembed = 'https://www.youtube.com/embed/' . $src_id;
            } else {
                $media_oembed = wp_oembed_get($url);
            }
            break;
        case 'oembed/vimeo':
            if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                $media_oembed = 'https://player.vimeo.com/video/' . basename($url);
            } else {
                $media_oembed = wp_oembed_get($url);
                $media_oembed = str_replace(basename($url), basename($url) . '?title=0&byline=0&portrait=0', $media_oembed);
            }
            break;
        case 'oembed/soundcloud':
            if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                //Get the JSON data of song details with embed code from SoundCloud oEmbed
                $getValues = wp_remote_fopen('http://soundcloud.com/oembed?format=js&url=' . $url . '&iframe=true');
                //Clean the Json to decode
                $decodeiFrame = substr($getValues, 1, -2);
                //json decode to convert it as an array
                $decodeiFrame = json_decode($decodeiFrame);
                preg_match('/src="([^"]+)"/', $decodeiFrame->html, $iframe_src);
                $media_oembed = $iframe_src[1];
            } else {
                $accent_color = $front_background_colors['accent'];
                $accent_color = str_replace('#', '', $accent_color);
                $getValues = wp_remote_fopen('http://soundcloud.com/oembed?format=js&url=' . $url . '&iframe=true');
                $decodeiFrame = substr($getValues, 1, -2);
                $decodeiFrame = json_decode($decodeiFrame);
                if (isset($decodeiFrame->html)) {
                    preg_match('/src="([^"]+)"/', $decodeiFrame->html, $iframe_src);
                    $iframe_url = str_replace('visual=true', 'visual=false', $iframe_src[1]);
                    $media_oembed = '<iframe width="100%" scrolling="no" frameborder="no" src="' . $iframe_url . '&color=' . $accent_color . '&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>';
                    if (strpos($iframe_url, 'playlist') !== false) {
                        $object_class = 'soundcloud-playlist';
                    } else {
                        $object_class = 'soundcloud-single';
                    }
                } else {
                    $media_oembed = '<img src="https://placeholdit.imgix.net/~text?txtsize=33&amp;txt=media+not+available&amp;w=500&amp;h=500" />';
                }
            }
            break;
        case 'oembed/spotify':
            if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                $get_url = parse_url($url);
                $break_spotify = explode('/', $get_url['path']);
                $media_oembed = 'https://embed.spotify.com/?uri=spotify' . implode(':', $break_spotify);
            } else {
                $media_oembed = wp_oembed_get($url);
                $media_oembed = preg_replace('#\\s(width)="([^"]+)"#', '', $media_oembed);
                $media_oembed = preg_replace('#\\s(height)="([^"]+)"#', '', $media_oembed);
                $object_class = 'object-size spotify';
            }
            break;
        case 'oembed/twitter':
            $url = 'https://api.twitter.com/1/statuses/oembed.json?id=' . basename($url);
            $json = wp_remote_fopen($url);
            $json_data = json_decode($json, true);
            $id = basename($json_data['url']);
            $html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $json_data['html']);
            $html = str_replace("&mdash; ", '', $html);
            $dom = new domDocument();
            $dom->loadHTML($html);
            $dom->preserveWhiteSpace = false;
            $twitter_content = $dom->getElementsByTagname('blockquote');
            $twitter_blockquote = '';
            $twitter_footer = '';
            foreach ($twitter_content as $item) {
                $twitter_content_inner = $item->getElementsByTagname('p');
                foreach ($twitter_content_inner as $item_inner) {
                    foreach ($item_inner->childNodes as $child) {
                        $twitter_blockquote .= $child->ownerDocument->saveXML($child);
                    }
                    $item_inner->parentNode->removeChild($item_inner);
                }
                foreach ($item->childNodes as $child) {
                    $twitter_footer .= $child->ownerDocument->saveXML($child);
                }
                $item->parentNode->removeChild($item);
            }
            $media_oembed = '<div class="twitter-item">
									<div class="twitter-item-data">
										<blockquote class="tweet-text pullquote">
											<p>' . $twitter_blockquote . '</p>';
            $media_oembed .= '<p class="twitter-footer"><i class="fa fa-twitter"></i><small>' . $twitter_footer . '</small></p>';
            $media_oembed .= '</blockquote>
									</div>
								</div>';
            $width = 1;
            $height = 0;
            $object_class = 'tweet object-size regular-text';
            break;
        case 'oembed/html':
            $author = $author_img = '';
            $width = 1;
            $height = 0;
            $poster = get_post_meta($id, "_uncode_poster_image", true);
            $poster_id = $poster;
            if ($poster !== '' && $with_poster || $lighbox_code) {
                $attr = array('class' => "avatar");
                $author_img = wp_get_attachment_image($poster, 'thumbnail', false, $attr);
                $author_img = '<figure class="gravatar">' . $author_img . '</figure>';
            }
            if ($excerpt) {
                $author = '<p><small>' . $excerpt . '</small></p>';
            }
            $media_oembed = '<blockquote class="pullquote">' . $author_img . '<p>' . esc_html($html) . '</p>' . $author . '</blockquote>';
            $object_class = 'regular-text object-size';
            $poster = '';
            break;
        case 'shortcode':
            $media_oembed = do_shortcode($url);
            $object_class = 'object-size shortcode';
            break;
        default:
            if (strpos($mime, 'audio/') !== false) {
                if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                    $media_oembed = $url;
                } else {
                    $object_class = 'object-size self-audio';
                    $media_oembed = apply_filters('the_content', '[audio src="' . $url . '"]');
                    $poster = get_post_meta($id, "_uncode_poster_image", true);
                    $poster_id = $poster;
                }
            } else {
                if (strpos($mime, 'video/') !== false) {
                    if (isset($poster) && $poster !== '' && $with_poster || $lighbox_code) {
                        $media_oembed = $url;
                    } else {
                        $videos = array();
                        $exloded_url = explode(".", strtolower($url));
                        $ext = end($exloded_url);
                        $videos[(string) $ext] = $url;
                        $alt_videos = get_post_meta($id, "_uncode_video_alternative", true);
                        if (!empty($alt_videos)) {
                            foreach ($alt_videos as $key => $value) {
                                $exloded_url = explode(".", strtolower($value));
                                $ext = end($exloded_url);
                                $videos[(string) $ext] = $value;
                            }
                        } else {
                            $videos = array('src' => '"' . $url . '"');
                        }
                        $video_src = '';
                        foreach ($videos as $key => $value) {
                            $video_src .= ' ' . $key . '=' . $value;
                        }
                        $object_class = 'object-size self-video';
                        $poster = get_post_meta($id, "_uncode_poster_image", true);
                        $poster_url = '';
                        if (isset($poster) && $poster !== '') {
                            $poster_attributes = uncode_get_media_info($poster);
                            if (isset($poster_attributes->metadata)) {
                                $media_metavalues = unserialize($poster_attributes->metadata);
                                $image_orig_w = $media_metavalues['width'];
                                $image_orig_h = $media_metavalues['height'];
                                $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false);
                                $poster_url = $resized_image['url'];
                            }
                        }
                        if ($poster_url !== '') {
                            $poster_url = ' poster="' . $poster_url . '"';
                        }
                        $media_oembed = apply_filters('the_content', '[video' . $video_src . $poster_url . ']');
                    }
                } else {
                    $media_oembed = wp_oembed_get($url);
                }
            }
            break;
    }
    if ($oembed_size['dummy'] == 0) {
        preg_match_all('/width="([^"]*)"/i', $media_oembed, $iWidth);
        $width = isset($iWidth[1][0]) ? $iWidth[1][0] : 1;
        preg_match_all('/height="([^"]*)"/i', $media_oembed, $iHeight);
        $height = isset($iHeight[1][0]) ? $iHeight[1][0] : 1;
        $oembed_size['dummy'] = round($height / $width * 100, 2);
    }
    return array('code' => $media_oembed, 'width' => $oembed_size['width'], 'height' => $oembed_size['height'], 'dummy' => $oembed_size['dummy'], 'type' => $media_type, 'class' => $object_class, 'poster' => $poster, 'poster_id' => $poster_id);
}
```

EXAMPLE #100   Show fileFile: [filter.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fzelenkoff%2Fprojectmath%2Fblob%2Fmaster%2Fbower_components%2Fjsxgraph%2Fplugins%2Fmoodle%2Ffilter.php) Project: [zelenkoff/projectmath](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fzelenkoff%2Fprojectmath)

```
 /**
  *
  * @get text between tags
  * @param string $tag The tag name
  * @param string $html The XML or XHTML string
  * @param int $strict Whether to use strict mode
  * @param string $encoding
  * @return array
  */
 private function getTextBetweenTags($tag, $html, $strict = 0, $encoding = "UTF-8")
 {
     global $PAGE, $CFG;
     if (!isset($CFG->filter_jsxgraph_divid)) {
         set_config('filter_jsxgraph_divid', 'box');
     }
     if (!isset($CFG->filter_jsxgraph_boardvar)) {
         set_config('filter_jsxgraph_boardvar', 'board');
     }
     if (!isset($CFG->filter_jsxgraph_width)) {
         set_config('filter_jsxgraph_width', '500');
     }
     if (!isset($CFG->filter_jsxgraph_height)) {
         set_config('filter_jsxgraph_height', '400');
     }
     // a new dom object
     $dom = new domDocument();
     $dom->formatOutput = true;
     // load the html into the object
     if ($strict == 1) {
         $dom->loadXML($html);
     } else {
         libxml_use_internal_errors(true);
         $htmlutf8 = mb_convert_encoding($html, 'HTML-ENTITIES', $encoding);
         $dom->loadHTML($htmlutf8);
         libxml_use_internal_errors(false);
     }
     // discard white space
     $dom->preserveWhiteSpace = false;
     $dom->strictErrorChecking = false;
     $dom->recover = true;
     // the tag by its tag name
     $content = $dom->getElementsByTagname($tag);
     if (count($content) > 0) {
         $PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/jsxgraphcore.js'));
     }
     // Iterate backwards through the jsxgraph tags
     $i = $content->length - 1;
     while ($i > -1) {
         $item = $content->item($i);
         // Read attributes
         $w = $item->getAttribute('width');
         if ($w == "") {
             $w = $CFG->filter_jsxgraph_width;
         }
         $h = $item->getAttribute('height');
         if ($h == "") {
             $h = $CFG->filter_jsxgraph_height;
         }
         $b = $item->getAttribute('box');
         if ($b == "") {
             $b = $CFG->filter_jsxgraph_divid . $i;
         }
         $brd = $item->getAttribute('board');
         if ($brd == "") {
             $brd = $CFG->filter_jsxgraph_boardvar . $i;
         }
         /* Create new div element containing JSXGraph */
         $out = $dom->createElement('div');
         $a = $dom->createAttribute('id');
         $a->value = $b;
         $out->appendChild($a);
         $a = $dom->createAttribute('class');
         $a->value = "jxgbox";
         $out->appendChild($a);
         $a = $dom->createAttribute('style');
         $a->value = "width:" . $w . "px; height:" . $h . "px; ";
         $out->appendChild($a);
         $t = $dom->createTextNode("");
         $out->appendChild($t);
         $out = $dom->appendChild($out);
         // Replace <jsxgraph> by <div>
         $item->parentNode->replaceChild($out, $item);
         $code = "";
         $needGXT = false;
         $url = $item->getAttribute('file');
         if ($url != "") {
             $code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromFile('" . $b . "', '" . $url . "', 'Geonext');";
             $needGXT = true;
         } else {
             $url = $item->getAttribute('filestring');
             if ($url != "") {
                 $code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromString('" . $b . "', '" . $url . "', 'Geonext');";
                 $needGXT = true;
             } else {
                 // Plain JavaScript code
                 $code = $item->nodeValue;
             }
         }
         // Place JavaScript code at the end of the page.
         $PAGE->requires->js_init_call($code);
         if ($needGXT) {
             $PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/GeonextReader.js'));
         }
         --$i;
     }
     // remove DOCTYPE
     $dom->removeChild($dom->firstChild);
     // remove <html><body></body></html>
     //$dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild);
     //return $dom->saveXML();
     $str = $dom->saveHTML();
     $str = str_replace("<body>", "", $str);
     $str = str_replace("</body>", "", $str);
     $str = str_replace("<html>", "", $str);
     $str = str_replace("</html>", "", $str);
     return $str;
 }
```

EXAMPLE #110   Show fileFile: [functions.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbasweerman%2Fxi%2Fblob%2Fmaster%2Ffunctions.php) Project: [basweerman/xi](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbasweerman%2Fxi)

```
function tagwrap($html, $width = 75, $break = "nr")
{
    $html = '<div>' . $html . '</div>';
    //using dom object
    $dom = new domDocument();
    //load the html into the object
    $dom->loadXML($html);
    // preserve white space
    $dom->preserveWhiteSpace = true;
    //getting all tags
    $content = $dom->getElementsByTagname("*");
    $html = "";
    foreach ($content as $item) {
        //wrapping contents of tags, function described above is used,
        //but you can use your own function or simple wordwrap() php function
        $item->nodeValue = mb_wordwrap($item->nodeValue, $width, $break);
        $html .= $dom->saveXML($item);
    }
    //return the results
    return $html;
    //html_entity_decode($html);
}
```
