Join WhatsApp ChannelJoin Now

HTML Tag Value Get in PHP

Hi Dev,

Today, i we will show you HTML tag value get in PHP. This article will give you simple example of HTML tag value get in PHP. you will HTML tag value get in PHP. In this article, we will implement a php get html element value. So let’s follow few step to create example of HTML tag value get in PHP.

Get HTML Element Value

index.php

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

Output:

This is codeplaners.com Example

Get HTML Element Value By ID

index.php

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

Output:

This is codeplaners.com Example 1
This is codeplaners.com Example 2

I hope it will assist you…

Recommended Posts