谁帮我写个php代码,比较2个字符串中包含与被包含的关系

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:55:44
$a="其我额人他以个分对方";
$b="我";

如何判断 $a中包含$b中的一个字符串
$b中的字符如果是$a中的任何一个那么输出 正确
$b中的字符如果没有一个是$a中的 那么输出 错误
现在$b中有个"我",$a中也有个"我",所以应该输出正确
但是代码怎么写呢

首先是输入的HTML文件
<html>
<head>
<title>
判断字符包含关系
</title>
</head>
<body>
<h1>请在下面两个文本框中输入不同字符串</h1>
<form method = "post"
action = "compare.php">
字符串一:<input type = "text"
name = "input1"
value = ""><br>
字符串二:<input type = "text"
name = "input2"
value = ""><br>
<input type = "submit"
value = "比较">
</form>
</body>
</html>
存为compare.html

然后是php文件
<html>
<head>
<title>
比较结果
</title>
</head>
<body>
<?php
//去掉字符串前后的空格
$input1 = trim($input1);
$input2 = trim($input2);
//比较两个字符串
if (strstr($input1,$input2)){
print "