HTML Tag Value Get in PHP

Hello Dev,

At present, i we are going to present you HTML tag worth get in PHP. This text offers you easy instance of HTML tag worth get in PHP. you’ll HTML tag worth get in PHP. On this article, we are going to implement a php get html component worth. So let’s comply with few step to create instance of HTML tag worth get in PHP.

Get HTML Component Worth

index.php


<?php
  
$htmlEle = "<html><physique><p id='paragraphID'>That is codeplaners.com Instance</p></physique></html>";
$domdoc = new DOMDocument();
$domdoc->loadHTML($htmlEle);
   
$pTagValue = $domdoc->getElementById('paragraphID')->nodeValue;
  
echo $pTagValue;

Output:


That is codeplaners.com Instance

Get HTML Component Worth By ID

index.php


<?php
  
$htmlEle = "<html><physique><p>That is codeplaners.com Instance 1</p><p>That is codeplaners.com Instance 2</p></physique></html>";
$domdoc = new DOMDocument();
$domdoc->loadHTML($htmlEle);
   
$pTags = $domdoc->getElementsByTagName('p');
  
foreach ($pTags as $p) {
    echo $p->nodeValue, PHP_EOL;
}

Output:


That is codeplaners.com Instance 1
That is codeplaners.com Instance 2

I hope it can help you…

Komentar

Postingan populer dari blog ini

PHP 8 Multiple Select Dropdown Example

Laravel 8 Get HTTP Hostname

JQuery Drag And Drop Menu Example