How to Get HTML Tag Value in PHP?
Hello,
In this example, i will show you php get html tag value example. We will look at example of php get html element value by id. In this article, we will implement a php get html element value. This post will give you simple example of how to get html tag value in php.
Here, i will give you simple two examples how to get html tag value in php and another how to get value by id in php. so let's see both code and output as bellow:
PHP Get HTML Element Value
index.php
<?php
$htmlEle = "<html><body><p id='paragraphID'>This is ItSolutionStuff.com Example</p></body></html>";
$domdoc = new DOMDocument();
$domdoc->loadHTML($htmlEle);
$pTagValue = $domdoc->getElementById('paragraphID')->nodeValue;
echo $pTagValue;
Output:
This is ItSolutionStuff.com Example
PHP Get HTML Element Value By ID
index.php
<?php
$htmlEle = "<html><body><p>This is ItSolutionStuff.com Example 1</p><p>This is ItSolutionStuff.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 ItSolutionStuff.com Example 1
This is ItSolutionStuff.com Example 2
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Generate QR Code using Google Chart API Example
- PHP Explode Every Character into Array Example
- PHP Remove Element from Array by Value Example
- How to Remove Last Element from Array in PHP?
- How to Remove First Element from Array in PHP?
- PHP Curl Delete Request Example Code
- How to Generate 4,6,8,10 Digit Random number in PHP?
- PHP - How to replace image src in a dynamic HTML string
- PHP Remove Directory and Files in Directory Example
- MySQL Query to Get Current Year Data Example
- How to Remove Null Values from Array in PHP?