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 ?
- PHP Convert Date String to Datetime Object
- Laravel Validation Different Value Example
- Jquery Redirect to URL After Specific Time Example
- User Roles and Permissions in Laravel Example
- How to Get Value of Selected Option in Vue JS?
- Laravel Change Password OLD Password Validation Example
- Vue JS Get String Length Example
- How to Active and Inactive Status in Laravel?