Any one can help me in finding any tag present in text as html format.
Ex: $text="<a href>the hero</a>";
find "<a
" is present in $text
or not in php.
Any one can help me in finding any tag present in text as html format.
Ex: $text="<a href>the hero</a>";
find "<a
" is present in $text
or not in php.
If you simply want to check for the presence of "<a" in a string use strpos. It is much faster than preg_* which must first compile a regular expression.
<?php
$exists = (strpos($text , '<a') !== false);
?>
For parsing HTML is best to use some kind of DOM parser, more info here: PHP HTML DOM Parser, but if your goal is only to check existence of html tag, preg_match
can be the solution:
$text="<a href>the hero</a>";
var_dump(preg_match("/\<a.*\>(.*?)\<\/a\>/si", $text));
Maybe:
if(str_replace("<a", "<a", $text)) {
echo "ok";
} else {
echo "not ok";
}