USA:From being Leader to Dealer American people have stopped to have leadership. I felt something sad, but it’s okay. USA country turned from leader to dealer. Some American wanted to make America great again.(MAGA) The world NEVER makes America great again.(NMAGA)
2020/6/14. The PHP language
Recently, I am learning PHP language.
PHP language is server-side language, and it is useful for web watching.
I wrote below code for web-watching to take the Mensa Japan exam.
(I am already Mensa member.)(And I don’t know this code will work well.)
Below code notifies with LINE app, so if you want to use it, you have to get permission from LINE development.
And you need to set some settings on your smartphone.
This is only test code, and if you want to use this code, you need some knowledge about Information technology.
And if you can use Linux crontab, this code runs every time.
I know you don’t need to take Mensa Japan exam.
This is just sample for getting a ticket which is difficult to get online.
First, I tried to use e-mail, but the e-mail’s security setting is too difficult.
So, I changed to use LINE app.
I took few weeks for writing below code, programming is so hard… Of course it is fun.
I started learning programming 2.5 years ago…
It was long time, but I got reached very far place from it…
(Code) *** is your LINE token.
<?php
$url = 'https://mensa.jp/exam/';
$filename = '/home/pi/Desktop/Mensa-exam-judge.txt';
$input = file_get_contents($url);
$prv = file_get_contents($filename);
$match1 = mb_strstr($input, '関東地方</h3>');
$match1 = str_replace(array(" ", " "), "", $match1);
$match1_1 = mb_strstr($match1, '</p>', true);
//var_dump($match1_1);
$match2 = mb_strstr($prv, '関東地方</h3> ');
$match2 = str_replace(array(" ", " "), "", $match2);
$match2_1 = mb_strstr($match2, '</p>', true);
//var_dump($match2_1);
if($match1_1 != $match2_1){
echo "NO";
define('LINE_API_URL' ,'https://notify-api.line.me/api/notify');
define('LINE_API_TOKEN’,’***’);
function post_message($message){
$data = http_build_query( [ 'message' => $message ], '', '&');
$options = [
'http'=> [
'method'=>'POST',
'header'=>'Authorization: Bearer ' . LINE_API_TOKEN . "\r\n"
. "Content-Type: application/x-www-form-urlencoded\r\n"
. 'Content-Length: ' . strlen($data) . "\r\n" ,
'content' => $data,
]
];
$context = stream_context_create($options);
$resultJson = file_get_contents(LINE_API_URL, false, $context);
$resultArray = json_decode($resultJson, true);
if($resultArray['status'] != 200) {
return false;
}
return true;
}
post_message("Mensa Exam!+ ${url}");
$fp = fopen($filename, 'w');
fwrite($fp, $input);
fclose($fp);
}else {
echo "YES";
}
?>