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 Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?
- Angular 9 Image Upload with Crop Example
- Files Upload on Button Click in PHP Dropzone Example
- PHP Dropzone Allow only One File to Upload Example
- PHP Dropzone Allow only Images to Upload Example
- PHP Dropzone Delete Uploaded File Example
- Livewire CRUD Laravel 7 Example