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

WBOY
Release: 2016-05-17 09:38:59
Original
804 people have browsed it

调用代码
<script></script>

js_bbs.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(\"

  • %s
  • \");\n", $myrow[0],cutstr($myrow[1], $length,"..")); 

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

    //截取字符函数
    function cutstr($string, $length, $dot = ' ...') { 
     $strcut = ''; 
     for($i = 0; $i  $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; 
     } 
     return $strcut.$dot; 
    }
    ?> 
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template