How to get HTML Tag Attribute Value in PHP?
In this article we will cover on how to implement php get html tag attribute value. Here you will learn how to get html tag attribute value in php. This article goes in detailed on php how to get html tag attribute value. i would like to share with you php regex get html tag attribute value. Here, Creating a basic example of php get custom attribute value from html.
Here, i will give you simple example how to get html tag attribute value in php. so let's see both code and output as bellow:
Example:
index.php
<?php
$htmlEle = "<html><body><p data-name='call'>This is ItSolutionStuff.com Example 1</p><p data-name='call2'>This is ItSolutionStuff.com Example 1</p></body></html>";
$domdoc = new DOMDocument();
$domdoc->loadHTML($htmlEle);
$xpath = new DOMXpath($domdoc);
$query = "//p[@data-name]";
$entries = $xpath->query($query);
foreach ($entries as $p) {
echo $p->getAttribute('data-name'), PHP_EOL;
}
Output:
call
call2
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
- How to Upgrade PHP Version from 7.4 to 8 in Ubuntu?
- PHP Array Get Previous Element from Current Key
- PHP Explode Every Character into Array Example
- PHP Remove Element from Array by Value Example
- PHP Curl Request with Username and Password Example
- PHP Curl Delete Request Example Code
- PHP Curl Get Request with Parameters Example
- How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?
- Laravel Bootstrap Tag System Example Tutorial
- HTML Tags are not Allowed in Textbox Validation using JQuery
- How to Get User IP Address in PHP?