简易小说阅读器 - 懒惰哥哥、首席妹妹、魔法学院?
闲着某天从手机里App SQlite 中导出了本小说,于是今天花了半小时做了个简易的小说阅读器。
没有样式,只有基本功能。源码在下面,没几行。
<?php
header("Content-type: text/html; charset=utf-8");
class cont {
function query(){
header("Content-type: text/plain; charset=utf-8");
$qa=$_GET['id'];
$sql =<<<EOF
SELECT content from abc where id= $qa;
EOF;
$db = new MyDB();
$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
echo $row['CONTENT'] ."\n";
}
}
}
class MyDB extends SQLite3
{
function __construct()
{
$this->open('db.db');
}
}
/////////////////////////////////////
$qa=isset($_GET['id']);
if(!$qa){
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "懒惰哥哥、首席妹妹、魔法学院?---加载完成!<br />";
}
$sql =<<<EOF
SELECT id,title from abc;
EOF;
$ret = $db->query($sql);
echo '
<head>
<script type="text/javascript">
function load(ids)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var string=xmlhttp.responseText;
string = string.replace(/\r\n/g,"<br>")
string = string.replace(/\n/g,"<br>");
string = string.replace(/\s/g," ");
document.getElementById("myDiv").innerHTML=string;
document.getElementById("pre").setAttribute("onclick", "load("+(ids-1)+");");
document.getElementById("next").setAttribute("onclick", "load("+(ids+1)+");");
document.getElementById("myDiv").style="display:block;";
document.getElementById("list").style="display:none;";
}
}
xmlhttp.open("GET","./?id="+ids,true);
xmlhttp.send();
}
function back(){
document.getElementById("myDiv").style="display:none;";
document.getElementById("list").style="display:block;";
}
</script>
</head>
<body>
<div id="list">
';
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
echo "<a href='#' onclick='load(". $row['id'] .");'>第". $row['id'];
echo "章 ". $row['TITLE'] ."</a><br />";
}
echo "</div><div id='myDiv'></div>";
echo '<button id="pre">上一页</button> <button id="back" onclick="back();">目录</button> <button id="next">下一页</button>';
$db->close();
}else
{
$cont =new cont();
$cont->query();
}
?>
版权声明:若无特殊注明,本文皆为《
CM部落 》原创,转载请保留文章出处。
本文链接:简易小说阅读器 - 懒惰哥哥、首席妹妹、魔法学院? https://www.itkz.cn/note/103.html
正文到此结束





胡萝卜