海河写的 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简单计算年龄的方法(周岁与虚岁)

本文实例讲述了php简单计算年龄的方法。分享给大家供大家参考,具体如下: /** * $date是时间戳 * $type为1的时候是虚岁,2的时候是周岁 */ function ge...

使用Xdebug调试和优化PHP程序之[1]

使用Xdebug调试和优化PHP程序之[1]

作者:Haohappy      MSN: haohappy at msn.com Blog: http://blog.csdn.net/hao...

解决文件名解压后乱码的问题 将文件名进行转码的代码

复制代码 代码如下: <?php $a=zip_open('other.zip'); while ($e=zip_read($a)){ $fz = zip_entry_filesi...

php获取发送给用户的header信息的方法

本文实例讲述了php获取发送给用户的header信息的方法。分享给大家供大家参考。具体分析如下: headers_list函数没有参数,并返回一个数组。返回的数组包含一个数字索引表,包含...

php生成验证码函数

php生成验证码函数

php生成验证码的函数,实用靠谱。先上下生成的验证码的效果图(这里生成的是全数字的验证码的示例效果): 下面是php生成验证码的源码: <?php sessio...