海河写的 Discuz论坛帖子调用js的php代码

yipeiwu_com6年前PHP代码库
调用代码
<script language="javascript" src="js_bbs.php?fid=1"></script>

js_bbs.php(放在根目录下) 内容


<?php
require ("bbs/config.inc.php");
//连接,选择数据库 
$link = mysql_connect( $dbhost,$dbuser,$dbpw) or die('Could not connect:'.mysql_error()); 
mysql_select_db($dbname) or die("Could not elect database"); 

$fid=$_GET["fid"]; 
//截取字符长度
$length=36;
//防止中文乱码 
mysql_query("set names 'gb2312'");
//执行SQL查询
$query = "SELECT tid,subject FROM cdb_threads where fid='$fid' order by lastpost desc LIMIT 10"; 
$result = mysql_query($query) or die("Query failed: ".mysql_error()); 
// 用 HTML显示结果 
while ($myrow = mysql_fetch_row($result)) 

 printf("document.writeln(\"<li><a href=\\\"bbs/viewthread.php?tid=%s&extra=page=1\\\ " target=\\\"_blank\\\">%s</a></li>\");\n", $myrow[0],cutstr($myrow[1], $length,"..")); 

// 释放结果集 
mysql_free_result($result); 
//关闭连接 
mysql_close($link); 

//截取字符函数
function cutstr($string, $length, $dot = ' ...') { 
 $strcut = ''; 
 for($i = 0; $i < $length - strlen($dot) - 1; $i++) { 
 $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; 
 } 
 return $strcut.$dot; 
}
?> 

相关文章

PHP中使用php5-ffmpeg撷取视频图片实例

前几天在玩 FFmpeg 的时后,突然发现 Ubuntu 上多了 php5-ffmpeg 这个扩充套件,就想来玩玩看,看好不好用,有两个结论: 读取影片取决于 FFmpeg 的支援性,如...

php使用sql server验证连接数据库的方法

本文实例讲述了php使用sql server验证连接数据库的方法。分享给大家供大家参考。具体分析如下: 当您连接到 SQL Server 时,SQL Server Driver for...

win10 apache配置虚拟主机后localhost无法使用的解决方法

win10 apache配置虚拟主机后localhost无法使用的解决方法

win10系统配置虚拟主机 1.用记事本或Sublime Text打开httpd.conf ctrl + f 搜索httpd-vhosts.conf 将 #Include conf...

PHP 的异常处理、错误的抛出及回调函数等面向对象的错误处理方法

异常处理用于在指定的错误(异常)情况发生时改变脚本的正常流程。这种情况称为异常。 PHP 5 添加了类似于其它语言的异常处理模块。在 PHP 代码中所产生的异常可被 throw 语句抛出...

浅析PHP开发规范

基本约定 源文件 代码使用<?php开头,忽略闭合标签?> 文件格式必须是无BOM UTF-8格式 一个文件只声明一种类型,如class和interfa...