</title>\" of a webpage. I\'dlike the form to compare the input of the" />
开发者

Compare and validate two seperate inputs with a PHP form

开发者 https://www.devze.com 2023-03-26 06:20 出处:网络
Scenario: A PHP form with two inputs, namely: Character Name: Character URL: The character name is within the \"<title></title>\" of a webpage. I\'dlike the form to compare the input of the

Scenario:

A PHP form with two inputs, namely:

Character Name:

Character URL:

The character name is within the "<title></title>" of a webpage. I'd like the form to compare the input of the character name with the name within the "<title></title>" of the submitted character URL, and if it's valid, post the data to a SQL db. That's it.

e.g

Character Name: GreatOne

Character URL: http://somewebsite.com/char/828282/

Within the page source is "<title>GreatOne - SomeWebsite&开发者_运维百科lt;/title>"

It needs to compare the two names and execute what I said above before posting the data to the SQL db. I'm not a programmer, and I can't go and learn a language just for this script, but I need it urgently to test something. Any help would be appreciated.


$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
}

Almost 1:1 from the http://www.php.net/ site


I would do something like this:

$url = $_post['characterurl']; $url = file_get_contents[$url]; preg_match('/title>(.*?)</title>/', $url, $url); $title = $url[1]; if($title==$_post['charactername']){ // post to db }else{ // do something other than post to db }

I would also put both title variables to lowercase and do the htmlspecialchars function too.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号