How to get html tag value in php

calendar_month 25 Jan 2023 | PHP


In this tutorial, you will learn how to get html tag value in php with example, if you don't know how to get html tag value such as header, paragraph or any other tag value. You can get html tag value by id or class in php. So, if you don't know how to get html tag value in php, just follow this post.

So, let's follow this example to get html tag value in php. I will give you a simple example to get html tag value in php.

index.php

<?php
$htmlEle = "<html><body><h1>Hello World</h1> <p id='para'>This is example paragraph</p></body></html>";
$domdoc = new DOMDocument();
$domdoc->loadHTML($htmlEle);

echo $domdoc->getElementById('para')->nodeValue;
?>

Output:

This is example paragraph
Ashwani Kumar

I'm a dedicated full-stack developer, entrepreneur, and proud owner of buildwithphp.com. I reside in India, where I draw inspiration to create helpful tutorials and tips for fellow artisans. I'm deeply passionate about technologies like Bootstrap, PHP, CodeIgniter, Laravel, Node, React, JavaScript, and jQuery. I believe in working hard consistently, which keeps me motivated and driven. Challenges are opportunities to learn, setbacks are lessons. I find inspiration in the endless potential of technology and aim to make a meaningful impact with my work.

Buddy! I hope you relished the tutorial, and it was good to see you again. Keep learning. Keep visiting.

Related Tutorials
View all