如何使用 php 检测字符串上的 html 标签?

Ann*_*Ann 2 html php yii2

我需要知道什么标签html有一个字符串,例如:

$string = '<a href="http://example.com/">Hello World!</a>'
$result= 'a';
Run Code Online (Sandbox Code Playgroud)

PHP中有函数吗?

cha*_*ool 5

您可以使用 preg_match :

 $result = preg_match("/<[^<]+>/",$string, $res);
Run Code Online (Sandbox Code Playgroud)