> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/wordpress/php-domdocument-examples.md).

# PHP domDocument Examples

## PHP domDocument Examples

**PHP domDocument - 30 examples found**. These are the top rated real world PHP examples of **domDocument** 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)Examples at hotexamples.com: 30FREQUENTLY 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)[![](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[TestBox (C#)](https://csharp.hotexamples.com/examples/-/TestBox/-/php-testbox-class-examples.html)[TabGroup (C#)](https://csharp.hotexamples.com/examples/Asa.Bar.App.BarItems/TabGroup/-/php-tabgroup-class-examples.html)[\_stprintf\_s (C++)](https://cpp.hotexamples.com/examples/-/-/_stprintf_s/cpp-_stprintf_s-function-examples.html)[nn\_send (C++)](https://cpp.hotexamples.com/examples/-/-/nn_send/cpp-nn_send-function-examples.html)[MockTransactionSubmitter (Go)](https://golang.hotexamples.com/examples/github.com.stellar.gateway.mocks/MockTransactionSubmitter/-/golang-mocktransactionsubmitter-class-examples.html)[NewGroupAdder (Go)](https://golang.hotexamples.com/examples/github.com.openshift.origin.pkg.auth.group/-/NewGroupAdder/golang-newgroupadder-function-examples.html)[HibernateDao (Java)](https://java.hotexamples.com/examples/org.springside.modules.orm.hibernate/HibernateDao/-/java-hibernatedao-class-examples.html)[Binding (Java)](https://java.hotexamples.com/examples/org.aspectj.org.eclipse.jdt.internal.compiler.ast/Binding/-/java-binding-class-examples.html)[to\_str (Python)](https://python.hotexamples.com/examples/topdish.lib.base.h/-/to_str/python-to_str-function-examples.html)[mblg\_to\_mw\_atkinson\_boore\_87 (Python)](https://python.hotexamples.com/examples/openquake.hazardlib.gsim.utils/-/mblg_to_mw_atkinson_boore_87/python-mblg_to_mw_atkinson_boore_87-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[Super\_User](https://hotexamples.com/examples/-/Super_User/-/php-super_user-class-examples.html)[fes\_allowed\_html\_tags](https://hotexamples.com/examples/-/-/fes_allowed_html_tags/php-fes_allowed_html_tags-function-examples.html)[SassDirectiveNode](https://hotexamples.com/examples/-/SassDirectiveNode/-/php-sassdirectivenode-class-examples.html)[updateResource](https://hotexamples.com/examples/-/-/updateResource/php-updateresource-function-examples.html)[fn\_http\_request](https://hotexamples.com/examples/-/-/fn_http_request/php-fn_http_request-function-examples.html)[targetBlanker](https://hotexamples.com/examples/-/-/targetBlanker/php-targetblanker-function-examples.html)[BreadthFirst](https://hotexamples.com/examples/fhaculty.graph.algorithm.search/BreadthFirst/-/php-breadthfirst-class-examples.html)[Invite](https://hotexamples.com/examples/zidisha.lender/Invite/-/php-invite-class-examples.html)[Distrito](https://hotexamples.com/examples/-/Distrito/-/php-distrito-class-examples.html)[OpenLayersModel](https://hotexamples.com/examples/-/OpenLayersModel/-/php-openlayersmodel-class-examples.html)Google BookmarkFacebookTwitterPrintEmailMoreEXAMPLE #10   Show fileFile: [TopratedProducts.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsanjeedha%2FEnterprise-Marketplace%2Fblob%2Fmaster%2FTopratedProducts.php) Project: [sanjeedha/Enterprise-Marketplace](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsanjeedha%2FEnterprise-Marketplace)

```
function fetch_data_from_html($remote_page)
{
    // Returns an array of products and ratings
    $product_rating_arr = array();
    $html = get_html($remote_page);
    $dom = new domDocument();
    $dom->loadHTML($html);
    $dom->preserveWhiteSpace = false;
    $tables = $dom->getElementsByTagName('table');
    $table = $tables->item(0);
    $rows = $table->getElementsByTagName('tr');
    $i = 0;
    foreach ($rows as $row) {
        if ($i != 0) {
            $columns = $row->getElementsByTagName('td');
            $product = $columns->item(0)->textContent;
            $rating = $columns->item(1)->textContent;
            $image = $columns->item(2)->textContent;
            $var = $product . "__" . $image;
            $product_rating_arr[$var] = $rating;
        }
        $i += 1;
    }
    return $product_rating_arr;
}
```

[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)EXAMPLE #20   Show fileFile: [User.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fechmaster%2Fdata%2Fblob%2Fmaster%2F%D0%9B%D0%B0%D0%B1%D1%8B+%D0%A0%D0%A3%D0%A1%D0%90%D0%9A%D0%9E%D0%92%2F%D0%9B%D0%B0%D0%B1%D1%8B+XML+%D0%A0%D1%83%D1%81%2F28%2FUser.php) Project: [echmaster/data](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fechmaster%2Fdata)

```
		public function checkLogin(){
			$document = new domDocument();
			$document->load("users/users.xml");
			$xpath = new domXpath($document);
			$nodelist = $xpath->query("/*/user[string(login) = '$this->login']");
			return ($nodelist->length == 0)?false:true; 
		}
```

[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/728x90.png)](https://www.redcrossblood.org/donate-blood/dlp/plasma-donations-from-recovered-covid-19-patients.html?utm_source=ezoic)EXAMPLE #30   Show fileFile: [rss.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvcgato29%2Fpoff%2Fblob%2Fmaster%2Frss.php) Project: [vcgato29/poff](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvcgato29%2Fpoff)

```
 function readContent()
 {
     $data = read_xml_file($this->server, $this->port, $this->url);
     if (strlen($data) > 0) {
         $dom = new domDocument();
         $dom->loadXML(substr($data, 0, strrpos($data, '>') + 1));
         $arrFeeds = array();
         $count = 0;
         foreach ($dom->getElementsByTagName('item') as $node) {
             if (function_exists('date_parse')) {
                 $date_raw = date_parse($node->getElementsByTagName('pubDate')->item(0)->nodeValue);
                 //$date = date('H:i j.m.Y', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
                 $date = date('j.m', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
             } else {
                 $date1 = explode(' ', $node->getElementsByTagName('pubDate')->item(0)->nodeValue);
                 $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
                 $months_n = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
                 $time = explode(':', $date1[4]);
                 //$date = $time[0] . ':' . $time[1] . ' ' . intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]) . '.' . $date1[3];
                 $date = intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]);
             }
             $itemRSS = array('title' => mb_convert_case(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('title')->item(0)->nodeValue) : $node->getElementsByTagName('title')->item(0)->nodeValue, MB_CASE_UPPER, "UTF-8"), 'description' => substr(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('description')->item(0)->nodeValue) : $node->getElementsByTagName('description')->item(0)->nodeValue, 0, 60), 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue);
             $itemRSS['date'] = $date;
             array_push($arrFeeds, $itemRSS);
             $count++;
             if ($count == $this->nr_of_posts) {
                 break;
             }
         }
         return $arrFeeds;
     }
     return null;
 }
```

EXAMPLE #40   Show fileFile: [ParserWspolrzedne.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka%2Fblob%2Fmaster%2Fapplication%2FParserWspolrzedne.php) Project: [Adeptus/porownywarka](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka)

```
 public function findWspolrzedne($adres, $miasto)
 {
     $adresTrim = trim($adres);
     $adresReplaceSpace = str_replace(' ', '+', $adresTrim);
     $LettersToChange = array('ó', 'ż', 'ź', 'ś', 'ę', 'ą', 'ł', 'ń', 'ć');
     $LettersChanged = array('o', 'z', 'z', 's', 'e', 'a', 'l', 'n', 'c');
     $adresWithoutPolishLetters = str_replace($LettersToChange, $LettersChanged, $adresReplaceSpace);
     $curl1 = curl_init();
     curl_setopt($curl1, CURLOPT_URL, "http://www.zumi.pl/namapie.html?qt=&loc={$miasto},+{$adresWithoutPolishLetters}&Submit=Szukaj&cId=&sId=");
     curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
     $stronaZumi = curl_exec($curl1);
     curl_close($curl1);
     $dom = new domDocument();
     @$dom->loadHTML($stronaZumi);
     $dom->preserveWhiteSpace = false;
     $szukana = array();
     $divs = $dom->getElementsByTagName('div');
     foreach ($divs as $div) {
         $script = $div->getElementsByTagName('script');
         $szukana[] = $script->item(0)->nodeValue;
     }
     foreach ($szukana as $text) {
         if (strpos($text, 'objDefLoc')) {
             $a = substr($text, -29);
             $letterToRemove = array(':', '"', 'y', 'x', '}');
             $wspolrzedne1 = str_replace($letterToRemove, '', $a);
             $poz = strpos($wspolrzedne1, ',');
             $dlugosc = substr($wspolrzedne1, $poz);
             $dlugosc = str_replace(',', '', $dlugosc);
             $szerokosc = substr($wspolrzedne1, 0, $poz);
             $wspolrzedne[] = "{$dlugosc},{$szerokosc}";
         }
     }
     return $wspolrzedne[0];
 }
```

[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)EXAMPLE #50   Show fileFile: [dz.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fechmaster%2Fdata%2Fblob%2Fmaster%2F%D0%9B%D0%B0%D0%B1%D1%8B+%D0%A0%D0%A3%D0%A1%D0%90%D0%9A%D0%9E%D0%92%2F%D0%9B%D0%B0%D0%B1%D1%8B+XML+%D0%A0%D1%83%D1%81%2Fdz.php) Project: [echmaster/data](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fechmaster%2Fdata)

```
function viewInfo($node)
{
    if ($_POST["model1"] == "telefon") {
        $nameEl = "телефона";
    }
    if ($_POST["model2"] == "noutbuk") {
        $nameEl = "ноутбука";
    }
    if ($_POST["model3"] == "printer") {
        $nameEl = "принтера";
    }
    echo "<tr>\n\t\t<td><b>Марка " . $nameEl . "</b>\n\t\t</td><td><b>Год выпуска</b>\n\t</td></tr>";
    $document = new domDocument("1.0", "utf-8");
    $document->load("test3.xml");
    $nodelist = $document->getElementsByTagName("model");
    $model = $nodelist->item($i);
    for ($i = 0; $i < $nodelist->length; $i++) {
        $model = $nodelist->item($i);
        if ($model->parentNode->nodeName == $node || $model->parentNode->nodeName == "asort:" . $node) {
            $name = $model->childNodes->item(0);
            $year = $model->childNodes->item(1);
            echo "<tr>\n\t\t\t\t<td>" . $name->nodeValue . "</td>\n\t\t\t\t<td align='center'>" . $year->nodeValue . "</td>\n\t\t\t</tr>";
        }
    }
}
```

EXAMPLE #60   Show fileFile: [Status.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frecipe%2Fscalr%2Fblob%2Fmaster%2Fapp%2Fsrc%2FScalr%2FUI%2FController%2FDashboard%2FStatus.php) Project: [recipe/scalr](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Frecipe%2Fscalr)

```
 public function getContent($params = array())
 {
     $awsCachePath = CACHEPATH . "/aws.status.cxml";
     $data = array();
     $neededLocations = array();
     $services = array('Amazon Elastic Compute Cloud', 'Amazon Relational Database Service', 'Amazon Simple Storage Service');
     $compliance = array('us-east-1' => array('name' => 'NA_block', 'filter' => array('N. Virginia', 'US Standard')), 'us-west-1' => array('name' => 'NA_block', 'filter' => 'N. California'), 'us-west-2' => array('name' => 'NA_block', 'filter' => 'Oregon'), 'sa-east-1' => array('name' => 'SA_block', 'filter' => ''), 'eu-west-1' => array('name' => 'EU_block', 'filter' => ''), 'ap-southeast-1' => array('name' => 'AP_block', 'filter' => 'Singapore'), 'ap-southeast-2' => array('name' => 'AP_block', 'filter' => 'Sydney'), 'ap-northeast-1' => array('name' => 'AP_block', 'filter' => 'Tokyo'));
     if (empty($params['locations'])) {
         $neededLocations = $this->getUsedLocations();
         $params['locations'] = $neededLocations;
     } else {
         $neededLocations = $params['locations'];
     }
     if (file_exists($awsCachePath) && time() - filemtime($awsCachePath) < 3600) {
         clearstatcache();
         $time = filemtime($awsCachePath);
         $data = (array) json_decode(file_get_contents($awsCachePath));
     } else {
         $html = @file_get_contents('http://status.aws.amazon.com');
         if ($html) {
             $dom = new domDocument();
             $dom->validateOnParse = false;
             @$dom->loadHTML($html);
             $dom->preserveWhiteSpace = false;
             foreach ($compliance as $compKey => $compValue) {
                 $div = $dom->getElementById($compValue['name']);
                 $tables = $div->getElementsByTagName('table');
                 $rows = $tables->item(0)->getElementsByTagName('tr');
                 foreach ($rows as $row) {
                     $cols = $row->getElementsByTagName('td');
                     if (preg_match('/(.*)(' . implode('|', $services) . ')(.*)/', $cols->item(1)->nodeValue)) {
                         $regionFilter = $compValue['filter'];
                         if (is_array($compValue['filter'])) {
                             $regionFilter = implode('|', $compValue['filter']);
                         }
                         if (preg_match('/(.*)(' . $regionFilter . ')(.*)/', $cols->item(1)->nodeValue)) {
                             $img = '';
                             $message = '';
                             if ($cols->item(0)->getElementsByTagName('img')->item(0)->getAttribute('src') == 'images/status0.gif') {
                                 $img = 'normal.png';
                             } else {
                                 $img = 'disruption.png';
                                 $message = $cols->item(2)->nodeValue;
                             }
                             $data[$compKey][substr(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), 0, strpos(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), ' ('))] = array('img' => $img, 'status' => $cols->item(2)->nodeValue, 'message' => $message);
                             $data[$compKey]['locations'] = $compKey;
                         }
                     }
                 }
             }
             file_put_contents($awsCachePath, json_encode($data));
         }
     }
     $retval = array('locations' => json_encode($neededLocations));
     foreach ($neededLocations as $value) {
         $retval['data'][] = $data[$value];
     }
     return $retval;
 }
```

[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)EXAMPLE #70   Show fileFile: [mxmltree.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjoshuacoddingyou%2Fphp%2Fblob%2Fmaster%2Fcore%2Fclasses%2Fmxmltree.php) Project: [joshuacoddingyou/php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjoshuacoddingyou%2Fphp)

```
 /**
  * Brief Description.
  * Complete Description.
  *
  * @param $file' (tipo) desc
  *
  * @returns (tipo) desc
  *
  */
 public function __construct($file = '', $options = 0)
 {
     $this->tree = null;
     $this->stack = array();
     // this keeps track of what tag level you're at
     $doc = new domDocument();
     $doc->preserveWhiteSpace = false;
     $doc->load($file, $options);
     $root = $doc->documentElement;
     $this->parse($doc);
 }
```

EXAMPLE #80   Show fileFile: [domxml\_php5.inc.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmichaelprem%2Fphc%2Fblob%2Fmaster%2Ftest%2Fsubjects%2Fbenchmarks%2Fphp_bs%2Fdomxml_php5.inc.php) Project: [michaelprem/phc](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmichaelprem%2Fphc)

```
function bench2()
{
    global $XML;
    $dom = new domDocument();
    $dom->loadxml($XML);
    $children = $dom->getElementsByTagName('title');
    foreach ($children as $v) {
        $arr[] = $v->nodeValue;
    }
    return $arr;
}
```

EXAMPLE #90   Show fileFile: [simplexml\_import\_dom\_refcount.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbadlamer%2Fhhvm%2Fblob%2Fmaster%2Fhphp%2Ftest%2Fslow%2Fsimplexml_import_dom_refcount.php) Project: [badlamer/hhvm](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbadlamer%2Fhhvm)

```
function main()
{
    $dom = new domDocument();
    $string = <<<END
<a>
  <b>c</b>
</a>
END;
    $dom->loadXML($string);
    $s = simplexml_import_dom($dom);
    $dom = null;
    var_dump((string) $s->b);
}
```

EXAMPLE #100   Show fileFile: [crawler.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fhenrytrager%2FTPCrawler%2Fblob%2Fmaster%2Fcrawler.php) Project: [henrytrager/TPCrawler](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fhenrytrager%2FTPCrawler)

```
function get_pre($url)
{
    $html = file_get_contents($url);
    // a new dom object
    $dom = new domDocument('1.0', 'utf-8');
    // load the html into the object ***/
    @$dom->loadHTML($html);
    //discard white space
    $dom->preserveWhiteSpace = false;
    $pre = $dom->getElementsByTagName('pre');
    //Get elements by desired tag.
    return htmlspecialchars($pre->item(0)->nodeValue);
}
```

[![](https://go.ezodn.com/charity/https/charity-ads.s3.amazonaws.com/charity_ads/300x250.png)](https://www.cormghana.org/sponsor?utm_source=ezoic)EXAMPLE #110   Show fileFile: [global\_functions.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBGCX067%2Ffaaa-multifac-svn-to-git%2Fblob%2Fmaster%2Fglobal_functions.php) Project: [BGCX067/faaa-multifac-svn-to-git](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBGCX067%2Ffaaa-multifac-svn-to-git)

```
function getCompteDisplay()
{
    $dom = new domDocument();
    $arr = array(utf8_decode('é') => "\\351", utf8_decode('è') => "\\350", utf8_decode('ç') => "\\347", utf8_decode('à') => "\\340", utf8_decode('ù') => "\\371");
    $clientdata = strtr($_SESSION['client'], $arr);
    $dom->loadXML($clientdata);
    if (!$dom) {
        echo "Error while parsing the document\n";
        exit;
    }
    $s = simplexml_import_dom($dom);
    return strtoupper($s->nom) . ' ' . strtoupper($s->prenom) . ',' . $s->clientid . ',' . $s->type;
}
```

EXAMPLE #120   Show fileFile: [htmltotext.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjanaece%2Fglobalclassroom4_clean%2Fblob%2Fmaster%2Fweb%2Fportal%2Flib%2Fhtmltotext.php) Project: [janaece/globalclassroom4\_clean](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjanaece%2Fglobalclassroom4_clean)

```
 public function __construct($html, $baseurl)
 {
     $doc = new domDocument();
     $doc->loadHTML($html);
     $this->body = $doc->getElementsByTagName('html')->item(0)->getElementsByTagName('body')->item(0);
     $this->lines = array();
     $this->line = (object) array('text' => '', 'wrap' => true, 'prefix' => "\n");
     $this->pre = 0;
     $this->indent = array();
     $this->baseurl = $baseurl;
     $this->links = array();
     $this->linkcount = 0;
 }
```

EXAMPLE #130   Show fileFile: [htmlcontent\_helper.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fe-gob%2Fchilesinpapeleo-instituciones%2Fblob%2Fmaster%2Fapplication%2Fhtmlcontent_helper.php) Project: [e-gob/chilesinpapeleo-instituciones](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fe-gob%2Fchilesinpapeleo-instituciones)

```
 function prepareContent($content)
 {
     if (!$content) {
         return '';
     }
     $dom = new domDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $content);
     $images = $dom->getElementsByTagName('img');
     foreach ($images as $image) {
         $src = $image->getAttribute('src');
         $image->setAttribute('src', site_url($src));
     }
     return $dom->saveHTML();
 }
```

EXAMPLE #140   Show fileFile: [api.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Falissonlinneker%2Fe-MEC-API%2Fblob%2Fmaster%2Fapi.php) Project: [alissonlinneker/e-MEC-API](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Falissonlinneker%2Fe-MEC-API)

```
 function get_instituicao_cursos($cod_endereco, $cod_instituicao)
 {
     $html = file_get_contents('http://emec.mec.gov.br/emec/consulta-ies/listar-curso-endereco/d96957f455f6405d14c6542552b0f6eb/' . base64_encode($cod_instituicao) . '/aa547dc9e0377b562e2354d29f06085f/' . base64_encode($cod_endereco) . '/list/1000');
     include_once './src/simple_html_dom.php';
     $dom = new domDocument();
     @$dom->loadHTML($html);
     $dom->preserveWhiteSpace = false;
     $tables = $dom->getElementsByTagName('tbody');
     foreach ($tables as $row) {
         $cols = $row->getElementsByTagName('td');
         $array[] = preg_replace("/[^A-Za-z]/", "", $cols->item(0)->nodeValue);
     }
     return $array;
 }
```

EXAMPLE #150   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 #160   Show fileFile: [HTML.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FMyPHPTools%2FPHPExcel%2Fblob%2Fmaster%2FClasses%2FPHPExcel%2FHTML.php) Project: [MyPHPTools/PHPExcel](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FMyPHPTools%2FPHPExcel)

```
 public function toRichTextObject($html)
 {
     $this->initialise();
     //	Create a new DOM object
     $dom = new domDocument();
     //	Load the HTML file into the DOM object
     //  Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
     $loaded = @$dom->loadHTML($html);
     //	Discard excess white space
     $dom->preserveWhiteSpace = false;
     $this->richTextObject = new PHPExcel_RichText();
     $this->parseElements($dom);
     return $this->richTextObject;
 }
```

EXAMPLE #170   Show fileFile: [dom-parseLicenseTable.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FDanielDobre%2Ffossology%2Fblob%2Fmaster%2Fsrc%2Ftesting%2Flib%2Fdom-parseLicenseTable.php) Project: [DanielDobre/fossology](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FDanielDobre%2Ffossology)

```
 /**
  * parseLicenseTbl
  * \brief given a fossology license histogram, parse it into license
  * names and Show links.
  *
  * @returns an array of associative arrays  with keys of:
  * count, showLink, textOrLink. the values will be the license count
  * the url of the Show link and whatever is in the next column.  This
  * can be text or a link or ?
  *
  * Sets property noRows.
  *
  * An empty array if no license histogram on that page,
  *
  */
 function parseLicenseTbl()
 {
     /*
      * Each table row has 3 td's in it. First is the license count, second
      * is the show link and third is the license name.
      */
     $dom = new domDocument();
     @$dom->loadHTML($this->page);
     /*** discard white space ***/
     $dom->preserveWhiteSpace = false;
     $table = $dom->getElementById($this->tableId);
     if (empty($table)) {
         $this->emptyTable = TRUE;
         //print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n";
         return $this->hList = array();
     }
     foreach ($table->childNodes as $tblChildNode) {
         $histogram = array();
         foreach ($tblChildNode->childNodes as $childNode) {
             if ($childNode->nodeName == 'td') {
                 if (is_numeric($childNode->nodeValue)) {
                     $histogram['count'] = trim($childNode->nodeValue);
                 }
                 if ($childNode->nodeValue == 'Show') {
                     $anchorList = $childNode->getElementsByTagName('a');
                     foreach ($anchorList as $anchorEle) {
                         $histogram['showLink'] = $anchorEle->getAttribute('href');
                     }
                 }
                 if (is_string($childNode->nodeValue)) {
                     $histogram['textOrLink'] = trim($childNode->nodeValue);
                 }
             }
         }
         // foreach($tblChildNode
         $this->hList[] = $histogram;
         $histogram = array();
     }
     // foreach
     // for tables with titles, the first row is empty as no childNodes match
     // what we are looking for, remove the first row.
     if ($this->title) {
         // remove empty 1st entry
         unset($this->hList[0]);
     }
     if (empty($this->hList)) {
         $this->noRows = TRUE;
     }
 }
```

EXAMPLE #180   Show fileFile: [Crawl.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjohnnymast%2Fredbox-crawl%2Fblob%2Fmaster%2FCrawl.php) Project: [johnnymast/redbox-crawl](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjohnnymast%2Fredbox-crawl)

```
 private function parseTags($tag = '', $source = "")
 {
     if (!$tag) {
         throw new Exception\CrawlException('Tag has type of null');
     }
     /*** a new dom object ***/
     $dom = new \domDocument();
     @$dom->loadHTML($source);
     /*** remove silly white space ***/
     $dom->preserveWhiteSpace = false;
     /*** get the links from the HTML ***/
     //  $tag->setTag('a');
     $tags = $dom->getElementsByTagName($tag);
     return $tags;
 }
```

EXAMPLE #190   Show fileFile: [UrlGetter.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjdblischak%2Fplos_altmetrics_study%2Fblob%2Fmaster%2FUrlGetter.php) Project: [jdblischak/plos\_altmetrics\_study](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjdblischak%2Fplos_altmetrics_study)

```
 private function asSimpleXml($str)
 {
     if (stripos($str, '<!DOCTYPE html') !== false) {
         // we've got to parse the html first
         $dom = new domDocument();
         // hack needed or else loadHTML won't work with utf-8:
         @$dom->loadHTML('<?xml encoding="UTF-8">' . $str);
         $simpleXmlObj = simplexml_import_dom($dom);
     } elseif (stripos($str, '<?xml') === 0) {
         $simpleXmlObj = simplexml_load_string($str);
     } else {
         throw new Exception("Can't parse as XML or HTML.");
     }
     return $simpleXmlObj;
 }
```

EXAMPLE #200   Show fileFile: [SimpleXMLTool.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsfedosimov%2FSimpleXMLTool%2Fblob%2Fmaster%2FSimpleXMLTool.php) Project: [sfedosimov/SimpleXMLTool](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsfedosimov%2FSimpleXMLTool)

```
 /**
  * Get XML by Array
  *
  * @param array $ar
  * @param array $options []
  *                       root_tag   - root tag wraping body xml (example root - <root>...</root>)
  *                       format     - true/false (formatting output XML)
  *                       version    - XML version (<?xml version="1"?>)
  *                       encode     - XML encode (<?xml encode="UTF-8"?>)
  *                       nohead     - XML output without "<?xml" header
  *
  * @return string
  */
 public static function createXML(array $ar, $options = array())
 {
     $root_tag = isset($options['root_tag']) ? $options['root_tag'] : 'root';
     $format = isset($options['format']) ? $options['format'] : true;
     $version = isset($options['version']) ? $options['version'] : '1.0';
     $encode = isset($options['encode']) ? $options['encode'] : 'UTF-8';
     $nohead = isset($options['nohead']) ? $options['nohead'] : false;
     $dom = new domDocument($version, $encode);
     $root = $dom->appendChild($dom->createElement($root_tag));
     self::createXMLElement($dom, $root, $ar);
     $dom->formatOutput = $format;
     if ($nohead) {
         return $dom->saveXML($root);
     }
     return $dom->saveXML();
 }
```

EXAMPLE #210   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 #220   Show fileFile: [facture\_amarrage\_top.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBGCX067%2Ffaaa-multifac-svn-to-git%2Fblob%2Fmaster%2Ffacture_amarrage_top.php) Project: [BGCX067/faaa-multifac-svn-to-git](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FBGCX067%2Ffaaa-multifac-svn-to-git)

```
function getCompteType()
{
    $dom = new domDocument();
    $arr = array(utf8_decode('é') => "\\351", utf8_decode('è') => "\\350", utf8_decode('ç') => "\\347", utf8_decode('à') => "\\340", utf8_decode('ù') => "\\371");
    $clientdata = strtr($_SESSION['client'], $arr);
    $dom->loadXML($clientdata);
    if (!$dom) {
        echo "Error while parsing the document\n";
        exit;
    }
    $s = simplexml_import_dom($dom);
    if ($s->type == "client") {
        return "C";
    } else {
        return "M";
    }
}
```

EXAMPLE #230   Show fileFile: [RealmStatus.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FGelatine%2FWoWRealmStatus%2Fblob%2Fmaster%2FRealmStatus.php) Project: [Gelatine/WoWRealmStatus](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FGelatine%2FWoWRealmStatus)

```
    /**
     * This function returns an associative array containing information 
     * about every WoW Server. 
     *
     * The associative array is in the following format:
     * "name" - Name of the server. 
     * "status" - Status of the server ("up" or "down")
     * "type" - Type of server (PvE, PvP, RP)
     * "population" - Low, Medium, High server status. 
     * "locale" - Location of WoW Server (United States by default)
     */
    function getAllServers() {

        if($this->SERVER_ARRAY == null) {

            $dom = new domDocument;
            $dom->loadHTML(file_get_contents($this->STATUS_URL));
            $dom->preserveWhiteSpace = false;

            $xpath = new DOMXPath($dom);

            $name = $xpath->query('//td[@class="name"]');
            $status = $xpath->query('//td[@class="status"]/div/@class');
            $type = $xpath->query('//td[@class="type"]/span');
            $population = $xpath->query('//td[@class="population"]/span');
            $locale = $xpath->query('//td[@class="locale"]');

            /* Generate the number of servers */
            $ctr = 0;
            foreach($name as $n) {
                $ctr++;
            }

            $serverArray = array();

            for($i=0;$i<$ctr;$i++) {

                $s = explode(" ", trim($status->item($i)->nodeValue));

                $info = array (
                    "name" => trim(utf8_decode($name->item($i)->nodeValue)),
                    "status" => $s[1],
                    "type" => substr(substr(trim($type->item($i)->nodeValue),0,-1),1),
                    "population" => trim($population->item($i)->nodeValue),
                    "locale" => trim(utf8_decode($locale->item($i)->nodeValue))
                );

                array_push($serverArray, $info);
            }

            $this->SERVER_ARRAY = $serverArray;
        }

        return $this->SERVER_ARRAY;
    }
```

EXAMPLE #240   Show fileFile: [nhrtools1.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FJosephMokano%2Fsomu-nhr%2Fblob%2Fmaster%2Fsystem%2Fapplication%2Fnhrtools1.php) Project: [JosephMokano/somu-nhr](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FJosephMokano%2Fsomu-nhr)

```
 function readhtml()
 {
     $dom = new domDocument();
     $dom->loadHTMLFile("docs/KUNNAMKUL.html");
     $dom->preserveWhiteSpace = false;
     $tables = $dom->getElementsByTagName('table');
     /*** get all rows from the table ***/
     $rows = $tables->item(0)->getElementsByTagName('tr');
     /*** loop over the table rows ***/
     $dataArray = array();
     foreach ($rows as $row) {
         /*** get each column by tag name ***/
         $cols = $row->getElementsByTagName('td');
         /*** echo the values ***/
         if ($cols->item(0)->nodeValue) {
             $tmpArray = array();
             $tmpArray[] = $cols->item(0)->nodeValue;
             $name = $cols->item(1)->getElementsByTagName('p');
             $tmpArray[] = $name->item(0)->nodeValue;
             $tmpstring = isset($name->item(1)->nodeValue) ? $name->item(1)->nodeValue : '';
             $tmpstring .= isset($name->item(2)->nodeValue) ? $name->item(2)->nodeValue : '';
             $tmpstring .= isset($name->item(3)->nodeValue) ? $name->item(3)->nodeValue : '';
             $tmpArray[] .= $tmpstring;
             //$tmpArray[]=$cols->item(1)->nodeValue;
             $bsdob = $cols->item(2)->getElementsByTagName('p');
             $tmpArray[] = $bsdob->item(0)->nodeValue;
             $tmpArray[] = isset($bsdob->item(1)->nodeValue) ? $bsdob->item(1)->nodeValue : '';
             $tmpArray[] = isset($bsdob->item(2)->nodeValue) ? $bsdob->item(2)->nodeValue : '';
             //$tmpArray[]=$bsdob->item(2)->nodeValue;
             $factorinfo = $cols->item(3)->getElementsByTagName('p');
             $tmpArray[] = isset($factorinfo->item(0)->nodeValue) ? $factorinfo->item(0)->nodeValue : '';
             $tmpArray[] = isset($factorinfo->item(1)->nodeValue) ? $factorinfo->item(1)->nodeValue : '';
             $dpan = $cols->item(4)->getElementsByTagName('p');
             $tmpArray[] = $dpan->item(0)->nodeValue;
             $tmpArray[] = isset($dpan->item(1)->nodeValue) ? $dpan->item(1)->nodeValue : '';
             $tmpArray[] = isset($dpan->item(2)->nodeValue) ? $dpan->item(2)->nodeValue : '';
             $dataArray[] = $tmpArray;
         }
     }
     $this->load->library('table');
     $tmpl = array('table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">');
     $this->table->set_template($tmpl);
     echo $this->table->generate($dataArray);
 }
```

EXAMPLE #250   Show fileFile: [myRoliksImporter.class.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fpycmam%2Fneskuchaik.ru%2Fblob%2Fmaster%2Fapps%2Fadmin%2FmyRoliksImporter.class.php) Project: [pycmam/neskuchaik.ru](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fpycmam%2Fneskuchaik.ru)

```
 private function _grab($date)
 {
     $content = new domDocument();
     // кривая разметка камы
     @$content->loadHTML(file_get_contents($this->_url . '?date=' . date('Y-m-d', $date)));
     $rows = $content->getElementsByTagName('tr');
     $result = array();
     for ($i = 2; $i < $rows->length; $i++) {
         $cols = $rows->item($i)->getElementsByTagName('td');
         $item = array('title' => $cols->item(1)->nodeValue, 'description' => 'Зал: ' . $cols->item(4)->nodeValue, 'fire_at' => date('Y-m-d ', $date) . trim(substr($cols->item(0)->nodeValue, 2)));
         if ($cols->item(4)->nodeValue == 1) {
             $item['description'] .= sprintf("\n\nЭконом: %s р.\nVIP: %s р.", $cols->item(2)->nodeValue, $cols->item(3)->nodeValue);
         } else {
             $item['description'] .= sprintf("\n\nЦена: %s р.", $cols->item(3)->nodeValue);
         }
         $result[] = $item;
     }
     return $result;
 }
```

EXAMPLE #260   Show fileFile: [ParserSamsung.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka%2Fblob%2Fmaster%2Fapplication%2FParserSamsung.php) Project: [Adeptus/porownywarka](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka)

```
 public function findMonitor($szukana)
 {
     $curl1 = curl_init();
     curl_setopt($curl1, CURLOPT_URL, "http://www.samsung.com/pl/function/espsearch/searchResult.do?keywords={$szukana}&amp;input_keyword={$szukana}");
     curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
     $strona1 = curl_exec($curl1);
     curl_close($curl1);
     $dom1 = new domDocument();
     @$dom1->loadHTML($strona1);
     $dom1->preserveWhiteSpace = false;
     $nazwa = array();
     $a = $dom1->getElementsByTagName('a');
     foreach ($a as $a) {
         $class = $a->getAttribute('class');
         $href = $a->getAttribute('href');
         $nazwa[$class] = $href;
     }
     $nazwa2 = $nazwa['arrow_blue'];
     $url = "{$nazwa2}&tab=specification";
     $curl2 = curl_init();
     curl_setopt($curl2, CURLOPT_URL, "{$url}");
     curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
     $strona2 = curl_exec($curl2);
     curl_close($curl2);
     $tabela = array();
     $dom2 = new domDocument();
     @$dom2->loadHTML($strona2);
     $dom2->preserveWhiteSpace = false;
     $nazwa = $dom2->getElementsByTagName('h1');
     $tabela['nazwa'] = $nazwa->item(0)->nodeValue;
     $rows = $dom2->getElementsByTagName('tr');
     foreach ($rows as $row) {
         $th = $row->getElementsByTagName('th');
         $nazwa = $th->item(0)->nodeValue;
         $nazwa2 = $th->item(1)->nodeValue;
         $td = $row->getElementsByTagName('td');
         $wartosc = $td->item(0)->nodeValue;
         $tabela[trim($nazwa)] = trim($wartosc);
         $tabela[trim($nazwa2)] = trim($wartosc);
     }
     $correctTable = $this->removeAllWrongValueFromTable($tabela);
     return $correctTable;
 }
```

EXAMPLE #270   Show fileFile: [ParserPrice.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka%2Fblob%2Fmaster%2Fapplication%2FParserPrice.php) Project: [Adeptus/porownywarka](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2FAdeptus%2Fporownywarka)

```
 public function getPrice($marka, $nazwa)
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, "http://www.ceneo.pl/Monitory;004+s{$marka}~~M{$nazwa}");
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $strona = curl_exec($curl);
     curl_close($curl);
     $dom = new domDocument();
     @$dom->loadHTML($strona);
     $dom->preserveWhiteSpace = false;
     $table = array();
     $bigs = $dom->getElementsByTagName('big');
     foreach ($bigs as $big) {
         $strong = $big->getElementsByTagName('strong');
         $cena = $strong->item(0)->nodeValue;
         $table[] = $cena;
     }
     return $table[0];
 }
```

EXAMPLE #280   Show fileFile: [imagecache.class.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcrazyyy%2Foctagram%2Fblob%2Fmaster%2Fsorces%2Fbck%2Fwp-content%2Fplugins%2Fajax-search-pro%2Fimagecache.class.php) Project: [crazyyy/octagram](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcrazyyy%2Foctagram)

```
 function parse_content()
 {
     $this->im = "";
     if ($this->content == "") {
         return;
     }
     $dom = new domDocument();
     @$dom->loadHTML($this->content);
     $dom->preserveWhiteSpace = false;
     @($images = $dom->getElementsByTagName('img'));
     if ($images->length > 0) {
         if ($images->length > $this->imagenum) {
             $this->im = $images->item($this->imagenum)->getAttribute('src');
         } else {
             $this->imagenum = 0;
             $this->im = $images->item(0)->getAttribute('src');
         }
     }
 }
```

EXAMPLE #290   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 #300   Show fileFile: [WSDLStruct.class.php](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmedali1990%2Fmedsite%2Fblob%2Fmaster%2Flib%2Fjelix-modules%2Fjsoap%2Fclasses%2FWSDLStruct.class.php) Project: [medali1990/medsite](https://hotexamples.com/site/redirect?url=https%3A%2F%2Fgithub.com%2Fmedali1990%2Fmedsite)

```
 /**
  * Adds an child element to the parent
  * @param string The name element
  * @param domNode 
  * @return domNode
  */
 private function addElement($name, $parent = false, $ns = false)
 {
     if ($ns) {
         $el = $this->doc->createElementNS($ns, $name);
     } else {
         $el = $this->doc->createElement($name);
     }
     if ($parent) {
         $parent->appendChild($el);
     }
     return $el;
 }
```
