This tutorial is focused on how to check string content have any html tag in php. step by step explain check if string contains html tags php. if you want to see example of php check if html tags exist in string then you are a right place. you can understand a concept of how to check if a string contains html tags in php. Let's see bellow example php check if string contains html tags.
Sometime we need to check if a string content have html tag in php for some logic. as my requirement. i have some content have tag and some content does not have any tags i need to check because there is a https link so i need to add anchor tag for that. so i search on google and finally find out solution.
I will give you simple two example with output so you can check that.
Example 1:
<?php
$myString = "Hi Rahul, <p>This is dog.</p>, hep";
if (isHTML($myString)) {
echo "There is a HTML Tag in String";
}else{
echo "No HTML Tag in String";
}
function isHtml($string)
{
return preg_match("/<[^<]+>/",$string,$m) != 0;
}
?>
Output:
There is a HTML Tag in String
Example 2:
<?php
$myString = "Hi Rahul, This is dog., hep";
if (isHTML($myString)) {
echo "There is a HTML Tag in String";
}else{
echo "No HTML Tag in String";
}
function isHtml($string)
{
return preg_match("/<[^<]+>/",$string,$m) != 0;
}
?>
Output:
No HTML Tag in String
I hope it can help you...
Do you like below Tutorials ?
- Angular 9 HttpClient Request with RxJS Observable Example
- How to Create Routing Module in Angular 9?
- How to Create Custom Directive in Angular 9?
- Print Iframe Content using JQuery Example
- Allow Only Numeric Values in Textbox using JQuery
- Codeigniter Confirmation Box Before Delete Item Example
- How to Use Sweet Alert in Codeigniter?
- Disable F5 Key And Browser Refresh Using Javascript