34 lines
905 B
PHP
34 lines
905 B
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>html标签匹配</title>
|
|
</head>
|
|
<body>
|
|
<form method="post" action="#">
|
|
<label for="html_code1">在这里输入html代码:</label>
|
|
<input type="text" name="html_code" id="html_code1" required/>
|
|
<input type="submit" value="提交">
|
|
</form>
|
|
<?php
|
|
$code = $_POST['html_code'] ?? '';
|
|
if (trim($code) != '') {
|
|
$regex = '/^<[\/]?[a-zA-z0-9 ="\';":]*>/';
|
|
// 貌似只匹配标签的部分
|
|
$preg_match = preg_match($regex, $code);
|
|
switch ($preg_match) {
|
|
case 1:
|
|
$code = str_replace('<', '<', $code);
|
|
$code = str_replace('>', '>', $code);
|
|
$code = str_replace('"', '"', $code);
|
|
echo $code;
|
|
break;
|
|
case 0:
|
|
echo '未找到html标签';
|
|
break;
|
|
default:
|
|
echo 'ERROR';
|
|
}
|
|
}
|
|
?>
|
|
</body>
|