How to get HTML tag value in PHP
PHP

How to get HTML tag value in PHP

In this article, we going to see how to get HTML tag value in PHP in a detail and a step by step with simple example.

You are at a right place to know how to get value.

Going to start with this topic you should know about HTML tag and PHP.

HTML tag is the root of HTML document and it contains all other HTML elements.

HTML elements example Paragraph, Anchor tags and many more.

And PHP is a script which is executed on a server.

As we are checking regarding getting of HTML tag value, from this many question come in mind.

Get Paragraph "p" tag value in PHP.

Syntax for Paragraph “<p>” tag.

Same thing is applied for all the tag in HTML.

Let’s Start with the topic to get HTML tag value in PHP.

There are two method we can achieve this.

First method is to use the strip_tag() function.

This function strips the string from HTML, PHP tags.

Below is code snippet from which you come to understand regarding strip tag function.

<?php
	$text = '<p>This is Sample paragraph text</p>';
	echo '<b>OUTPUT :<b/>'.''.strip_tags($text);
	echo "\n";
?>

Second method is using form inside the HTML tag.

There are 3 input field in the form of one is type of text, another is hidden and last submit button.

In the hidden field add paragraph text that you want to get value in PHP on form POST or GET method.

Just check with the condition for display the output of HTML tag value.

From Below code you can understand easily in which both method is added.

<!doctype html>
<html lang="en">
<head>
 <title>How to get HTML tag value in PHP</title>
</head>
<body>
<div style="background-color:#e5bcbc;padding:10px;" align="center">
	
	<h1>How to get HTML tag value in PHP:</h1><br/>
	<b style="color:white;">First Method Using strip_tags() :</b>
	<br/>
	<?php
		$text = '<p>This is Sample paragraph text</p>';
		echo '<b>OUTPUT :<b/>'.''.strip_tags($text);
		echo "\n";
	?>
	<br/><br/>
	<b style="color:white;">Second Method:</b>
	<br/>
	<?php 
		if(isset($_POST['btnSubmit']) && $_POST['btnSubmit'] == 'Submit'){
			echo $_POST['txtTxt'].''. $_POST['txtPara'];
		}
	?>
	<br/>
	<form action="" method="post">
		<p>This is sample paragraph text</p>
		<Input type="hidden" name="txtPara" value="This is sample paragraph text">
		<input type="text" name="txtTxt" readonly value="Paragraph tag value is :">
		<input type="submit" name="btnSubmit" value="Submit">
	</form>
</div>
</body>
</html>

Get anchor tag value in PHP

Below is OUTPUT of the code you can understand.

Get HTML Tag Value in PHP
Get HTML Tag Value in PHP

Conclusion:

Finally, we done with point of getting HTML tag value in PHP.

I hope you like this article and if you have any queries regarding this topic, please comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *