场景:
具有两个输入的PHP表单,即:
字符名称:
字符URL:
字符名称位于网页的"<title></title>"中。我希望表单将字符名称的输入与提交的字符URL的"<title></title>"中的名称进行比较,如果有效,则将数据发布到SQL数据库。就是这样。
例如
角色名称:GreatOne
字符URL:http://somewebsite.com/char/828282/
页面来源为"<title=GreatOne-SomeWebsite</title>">
在将数据发布到SQL数据库之前,它需要比较这两个名称并执行我上面所说的内容。我不是程序员,我不能仅仅为了这个脚本去学习一种语言,但我迫切需要它来测试一些东西。如有任何帮助,我们将不胜感激。
$filename = $CharacterUrl;
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
if (strstr($contents, $CharacterName)) {
// do something because whatever their name is appears in the contents of the url
} else {
// they don't exist
}
与http://www.php.net/站点
我会这样做:
$url=$_post['characterurl'];$url=file_get_contents[$url];preg_match('/title>(.*?(<title>/',$url,$url(;$title=$url[1];if($title==$_post['charactername']({//发布到数据库}其他{//做一些其他事情而不是发布到数据库}
我还将两个标题变量都小写,并执行htmlspecialchar函数。