Skip to content

Instantly share code, notes, and snippets.

@thaiall
Created February 3, 2017 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thaiall/5f424d021c203b828710bdeaadee3c03 to your computer and use it in GitHub Desktop.
Save thaiall/5f424d021c203b828710bdeaadee3c03 to your computer and use it in GitHub Desktop.
สคลิ๊ปอ่านข้อมูลจาก ratings.list แบบ plain text ที่เผยแพร่โดย imdb.com มาแสดงผลในเว็บเพจแบบตาราง แบ่งหน้าละ 50 รายการ และมีลิงค์ค้น title ในฐานข้อมูล imdb.com ผ่านชื่อเรื่อง โดยปรับภาษาให้แสดงตัวอักษรชื่อเรื่อง ผ่าน html ที่ใช้รหัส ord() เพื่อแสดงอักษรพิเศษ เช่นเรื่อง 8½ (1963) ในรายการที่ 230
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Ratings in imdb.com</title>
<meta http-equiv="content-type" content="text/html;charset=windows-874" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /><meta http-equiv="cache-control" content="max-age=2592000, public" />
<meta name="keywords" content="ratings,list,imdb,internet,movie,database,imdb.com" />
<meta name="description" content="ratings in imdb.com" />
<link type="text/css" rel="stylesheet" href="rsp62.css"><link rel="icon" type="image/x-icon" href="rsp.ico" />
</head><body id="main">
<table class="mytable">
<tr style="text-align:center;background-color:gray;color:white;"><td>No</td><td>Distribution</td><td>Votes</td><td>Rating</td><td>Title</td></tr>
<?php
$id = 0;
$cntline = 0;
$idperpage = 50;
if (!isset($_GET["page"]) || $_GET["page"] < 0) $page = 1; else $page = $_GET["page"];
//
// $strFileName = "ratings.list";
$strFileName = "ratings.list.sam";
$obj = fopen($strFileName, 'r');
if ($obj) {
while (!feof($obj)) {
$file = fgets($obj, 4096);
$point = preg_split("/[.]/",substr($file,26));
$cntline++;
if (substr($file,0,6) == " " && in_array(strlen($point[0]),array(2,3))) {
$id++;
$start = (($page - 1) * $idperpage) + 1;
$stop = ($page * $idperpage);
if($id >= $start && $id <= $stop) {
echo "<tr><td align=right>$id</td>";
echo "<td>". substr($file,6,10). "</td>";
echo "<td align=right>". substr($file,17,10) ."</td>";
echo "<td align=center>". substr($file,27,4) ."</td>";
echo "<td><a href=http://www.imdb.com/find?q=". urlencode(substr($file,32,strlen($file) - 32)) . ">";
for($j = 0; $j < strlen(substr($file,32,strlen($file) - 32)); $j++) {
echo "&#".ord(substr(substr($file,32,strlen($file) - 32),$j,1)).";";
}
echo "</a></td></tr>";
}
}
}
fclose($objFopen);
}
echo '<tr><td colspan=5 style="background-color:white;color:blue;">page : ';
$totalpage = round(($id / $idperpage) + 0.5);
for ($i = 1;$i <= $totalpage; $i++) {
if(in_array($i ,array(1,2,$totalpage,$totalpage - 1,$page,$page - 1, $page + 1))) {
if ($page == $i) $thispage = "! "; else $thispage ="";
echo "<". $thispage . "a href=ratings.php?page=$i>$i</a> | ";
}
if($page > 4 && $i == 2) echo " . . |";
if($page < ($totalpage - 3) && $i == ($totalpage - 3)) echo " . . | ";
}
echo "<br/>จำนวนข้อมูลในฐานข้อมูล $id รายการ<br/>จำนวนบรรทัดในฐานข้อมูล $cntline บรรทัด</td></tr>";
?>
</table>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment