ubb代码调换函数,收音和录音查询程序

<?
function cuturl($url) {
$length = 65;
$urllink = “<a href=””.(substr(strtolower($url), 0, 4) == ‘www.’ ?
“” : $url).'” target=”_blank”>’;
if(strlen($url) > $length) {
$url = substr($url, 0, intval($length * 0.5)).’ … ‘.substr($url, –
intval($length * 0.3));
}
$urllink .= $url.'</a>’;
return $urllink;
ubb代码调换函数,收音和录音查询程序。}
echo cuturl(“/”);
echo “<br>”;
echo cuturl(“www.fcxx.net/”);
echo “<br>”;
echo cuturl(“www.etoow.com”);
echo “<br>”;
?>

<?php
function ubb($string) {
  $searcharray[‘bbcode_regexp’] = array(
   “/s*[quote][nr]*(.+?)[nr]*[/quote]s*/is”,
   “/([box=(#[0-9A-F]{6}|[a-z]+)])[nr]*(.+?)[nr]*([/box])/is”,
   “/[url]s*([www.|https?://|ftp://|gopher://|news://|telnet://|rtsp://|mms://){1}([^[“‘]+?)s*[/url]/ie]()”,
   “/[url=www.([^[“‘]+?)](.+?)[/url]/is”,
   “/[url=(https?|ftp|gopher|news|telnet|rtsp|mms){1}://([^[“‘]+?)](.+?)[/url]/is”,
   “/[email]s*([A-Za-z0-9-_.]+)@([A-Za-z0-9-_]+[.][A-Za-z0-9-_.]+)s*[/email]/i”,
   “/[email=([A-Za-z0-9-_.]+)@([A-Za-z0-9-_]+[.][A-Za-z0-9-_.]+)](.+?)[/email]/is”,
   “/[color=([^[]+?)]/i”,
   “/[size=([^[]+?)]/i”,
   “/[font=([^[]+?)]/i”,
   “/[align=([^[]+?)]/i”,
   “/[center]/i”,
   “/[swf]s*([^[]+?)s*[/swf]/ies”,
   “/[img]s*([^[]+?)s*[/img]/ies”,
   “/[img=(d{1,3})[x|,](d{1,3})]s*([^[]+?)s*[/img]/ies”
  );
  $replacearray[‘bbcode_regexp’] = array(
   “<br><br><center><table border=”0″ width=”90%”
cellspacing=”0″
cellpadding=”0″><tr><td>  Quote:</td></tr><tr><td><table
border=”0″ width=”100%” cellspacing=”1″ cellpadding=”10″
bgcolor=””.BORDERCOLOR.””><tr><td width=”100%”
bgcolor=””.ALTBG2.””
style=”word-break:break-all”>\1</td></tr></table></td></tr></table></center><br>”,
   “<blockquote style=”background-color: \2
;”><span
class=”bold”>$title</span>\3</blockquote>”,
   “cuturl(‘\1\2’)”,
   “<a href=”http://www.\\1″
target=”_blank”>\2</a>”,
   “<a href=”\1://\2″
target=”_blank”>\3</a>”,
   “<a
href=”mailto:\1@\2″>\1@\2</a>”,
   “<a
href=”mailto:\1@\2″>\3</a>”,
   “<font color=”\1″>”,
   “<font size=”\1″>”,
   “<font face=”\1″>”,
   “<p align=”\1″>”,
   “<p align=”center”>”,
   “bbcodeurl(‘\1’, ‘ <img
src=”images/flash.gif”
align=”absmiddle”> <a href=”%s” target=”_blank”>Flash:
%s</a> ‘)”,
   “bbcodeurl(‘\1’, ‘<img src=”%s” border=”0″
onload=”if(this.width>screen.width*0.7) {this.resized=true;
this.width=screen.width*0.7; this.alt=’Click here to open new
window’;}” onmouseover=”if(this.resized) this.style.cursor=’hand’;”
onclick=”if(this.resized) {window.open(‘%s’);}”>’)”,
   “bbcodeurl(‘\3’, ‘<img width=”\1″
height=”\2″ src=”%s” border=”0″>’)”
  );

最轻松易行的字符截取函数是用php自带的substr()

 代码如下

  $searcharray[‘bbcode_str’] = array(
   ‘[/color]’, ‘[/size]’, ‘[/font]’, ‘[/align]’, ‘[b]’,
‘[/b]’,
   ‘[i]’, ‘[/i]’, ‘[u]’, ‘[/u]’, ‘[list]’, ‘[list=1]’,
‘[list=a]’,
   ‘[list=A]’, ‘[*]’, ‘[/list]’,'[/center]’
  );

事实上,PHP原生就有多charset下字符截取方案,额,所以正是以此样子…??.

*/
header(‘content-type: text/html; charset=utf-8’);
require(‘function.php’);

  $replacearray[‘bbcode_str’] = array(
   ‘</font>’, ‘</font>’, ‘</font>’, ‘</p>’,
‘<b>’, ‘</b>’, ‘<i>’,
   ‘</i>’, ‘<u>’, ‘</u>’, ‘<ul>’, ‘<ol
type=1>’, ‘<ol type=a>’,
   ‘<ol type=A>’, ‘<li>’,
‘</ul></ol>’,'</p>’
  );                 
  $string = str_replace($searcharray[‘bbcode_str’],
$replacearray[‘bbcode_str’],
preg_replace($searcharray[‘bbcode_regexp’],
$replacearray[‘bbcode_regexp’], $string));

Multibyte String Functions函数族中,

$url = strtolower(trim($_get[‘url’]));
$lm = intval($_get[‘lm’]);
$pn = intval($_get[‘pn’]);

                return $string;
}

string mb_substr ( string $str , int $start [, int $length [, string
$encoding ]] )  用来字符串截取

$url = getshorturl($url);

function bbcodeurl($url, $tags) {
 if(!preg_match(“/<.+?>/s”,$url)) {
  if(!in_array(strtolower(substr($url, 0, 6)), array(‘http:/’,
‘ftp://’, ‘rtsp:/’, ‘mms://’))) {
   $url = ‘;
  }
  return str_replace(‘submit’, ”, sprintf($tags, $url, $url));
 } else {
  return ‘ ‘.$url;
 }
}

int mb_strlen ( string $str [, string $encoding ] )  重返字符串长度

if (empty($pn)) $pn = 1;

function cuturl($url) {
 $length = 65;
 $urllink = “<a href=””.(substr(strtolower($url), 0, 4) == ‘www.’ ?
“” : $url).'” target=”_blank”>’;
 if(strlen($url) > $length) {
  $url = substr($url, 0, intval($length * 0.5)).’ … ‘.substr($url, –
intval($length * 0.3));
 }
 $urllink .= $url.'</a>’;
 return $urllink;
}
?>

但它只扶助数字与字母不援救中文

switch ($lm) {
 case 1 :
  $timestr = ’24小时’;
  break;
 case 7 :
  $timestr = ‘一星期’;
  break;
 case 30 :
  $timestr = ‘一个月’;
  break;
 case 360 :
  $timestr = ‘一年’;
  break;
 default :
  $timestr = ‘所不经常间’;
  break;
}
?>
<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en”
“”>
<html xmlns=””>
<head>
<?php
if (empty($url)) {
?>
<title>35dir百度近些日子起用查询-35分类目录</title>
<meta name=”keywords” content=”百度以来圈定查询” />
<meta name=”description”
content=”百度以来圈定查询可按钦赐时期段(这两天24钟头、一星期、叁个月、一年、所一时间)查询,令你及时驾驭网站在某有时间段内的任用情形。”
/>
<?php
} else {
?>
<title><?php echo $url;?>百度眼下<?php echo $timestr;
?>收音和录音详细的情况-35分类目录</title>
<meta name=”keywords” content=”<?php echo $url;
?>,百度多年来录取查询” />
<meta name=”description” content=”<?php echo $url;
?>,百度以来<?php echo $timestr; ?>收音和录音查询结果。” />
<?php
}
?>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″
/>
<meta name=”copyright” content=”powered by 111cn.net” />
<meta http-equiv=”pragma” content=”no-cache” />
<script type=”text/网页特效”
src=”jquery.js”></script>
<script type=”text/jscript”>
function checkfrm() {
 if ($(“#url”).attr(“value”) == “”) {
  alert(“请输入要询问的域名!”);
  $(“#url”).focus();
  return false;
 } else {
  var reexp =
/^([a-z0-9-]{1,}.)?[a-z0-9-]{2,}.([a-z0-9-]{1,}.)?[a-z0-9]{2,}$/i;
  if (!reexp.test($(“#url”).attr(“value”))) {
   alert(“请输入正确的域名!”);
   $(“#url”).focus();
   return false;
  }
 }
 return true;
}
</script>
<link
href=”skin/style.css教程”
rel=”stylesheet” type=”text/css” />
</head>

实例

<body>
<div id=”topbar”>网站导航:<a href=””
target=”_blank”>35分类目录</a> | <a
href=”” target=”_blank”>open
directory</a></div>
<div id=”container”>
 <div id=”header”>
     <a class=”logo” href=””
title=”35dir百度近年来援引查询”></a>
     <div id=”search”>
          <form name=”myso” method=”get” action=”” onsubmit=”return
checkfrm();”>
   <span style=”font: bold 16px normal;”>;
<input name=”url” id=”url” type=”text” size=”50″ class=”sipt”
value=”<?php echo $url;?>” />
                <input type=”hidden” name=”lm” value=”1″ />
    <input type=”submit” class=”sbtn” value=”查 询” />
              <div
class=”tips教程”>示例:<a
href=”javascript: void(0);” onclick=”$(‘#url’).attr(‘value’,
‘111cn.net’)”>111cn.net</a>,<a href=”javascript: void(0);”
onclick=”$(‘#url’).attr(‘value’,
‘www.111cn.net’)”>www.111cn.net</a>,带”www”与不带”www”的询问结果分裂</div>
          </form>
        </div>
 </div>
    <?php
 if (!empty($url)) {
 ?>
    <div class=”tool”><strong>定时间段查询:</strong>
<a href=””>前段时间24钟头</a>  <a
href=””>近来一星期</a>  <a
href=””>最近二个月</a>  <a
href=””>这段日子一年</a>  <a
href=””>总收音和录音量</a></div>
  <div id=”mainer”>
     <?php
  $query_url =
‘;
  $line_arr = @file($query_url);
   
  $content = implode(‘###’, $line_arr);
  $content = @mb_convert_encoding($content, ‘utf-8’, ‘gb2312’);
  
  //index
  if (preg_match(‘/找到相关网页(.*?)篇/i’, $content, $index)) {
   $baiduindex = str_replace(‘约’, ”, $index[1]);
  } else {
   $baiduindex = ‘-‘;
  }
  ?>
     <div class=”content”>
      <h2>百度在近期 <font color=”#ff6600″><?php echo
$timestr; ?></font> 内共收录了网址( <a href=”<?php echo
getfullurl($url); ?>” target=”_blank”><?php echo $url;
?></a> ) <font color=”#ff6600″><?php echo
$baiduindex; ?></font> 个页面</h2>
         <div>
   <?php
   $content = strstr($content, ‘<table cellpadding=”0″
cellspacing=”0″ class=”result”‘);
   $end = strpos($content, ‘<div id=”search”>’);
   $content = substr($content, 0, $end);
   
   $item_arr = explode(‘<tr><td class=f>’, $content);
 
   //showpage
   if (preg_match(‘/<p id=”page”>(.*?)</div>/’, $content,
$page_arr)) {
    $showpage = str_replace(‘s?wd=site%3a’, ‘?url=’,
$page_arr[1]);
    $showpage = str_replace(‘[‘, ”, $showpage);
    $showpage = str_replace(‘]’, ”, $showpage);
   }
 
   $i = 0;
   $strhtml = ‘<ul class=”sitelist”>’;
   foreach ($item_arr as $item) {
    if (preg_match(‘/<a  onmousedown=”(.*?)” href=”(.*?)” 
target=”_blank” ><font
size=”3″>(.*?)</font></a><br><font
size=-1>(.*?)<font color=”#008000″>(.*?)</font> –
<a href=”(.*?)”  target=”_blank”  class=”m”>/i’, $item,
$siteinfo)) {
     $sitename = $siteinfo[3];
     $siteurl = $siteinfo[2];
     $sitedesc = $siteinfo[4];
     $siteltime = $siteinfo[5];
     $sitecache = $siteinfo[6];
     
     $strhtml .= ‘<li>’;
     $strhtml .= ‘<strong><em>’.$i.’.</em><a
href=”‘.$siteurl.'”
target=”_blank”>’.$sitename.'</a></strong>’;
     $strhtml .= ‘<p>’.$sitedesc.'</p>’;
     $strhtml .= ‘<address>’.$siteltime.’ – <a
href=”‘.$sitecache.'”
target=”_blank”>百度快速照相</a></address>’;
     $strhtml .= ‘</li>’;
    }
    $i++;
   }
   $strhtml .= ‘</ul>’;
   $strhtml .= ‘<div
class=”showpage”>’.$showpage.'</div>’;
 
   echo $strhtml;
   ?>
      </div>
  </div>
  </div>
    <?php
    }
 ?>
  
</div>
</body>
</html>

UTF8普通话字符截断

function文件

 代码如下

<?php
function getfullurl($url) {
 if ($url != “”) {
  $url_parts = parse_url($url);
  if ($url_parts[‘scheme’] == “”) {
   $url = “http://”.$url;
  }
 }
 return $url;
}
 
function getshorturl($url) {
 if ($url != “”) {
  $url_parts = parse_url($url);
        if ($url_parts[‘host’] == “”) {
   $url = $url_parts[‘path’];
  } else {
            $url = $url_parts[‘host’];
        }
 }
 return $url;
}
 
function format_number($number) {
 if ($number == ”) return “-“;
 $nlen = strlen($number);
 while ($nlen > 3) {
  $fnumber = “,”.substr($number, $nlen – 3, 3).$fnumber;
  $number = substr($number, 0, -3);
  $nlen = strlen($number);
 }
  
 if ($nlen <= 3) {
  $fnumber = $number.$fnumber;
 }
 return $fnumber;
}
?>

<?php
 /* UTF-8国语字符截断程序 */
 
 
 $str = “123那是测量试验字符串”;
 $str1 = “()()”;
 echo subUTF8str($str,0,3).”<br>”;
 echo subUTF8str($str,0,4).”<br>”;
 echo subUTF8str($str1,0,4).”<br>”;
 echo subUTF8str($str1,0,10).”<br>”;
 
 function subUTF8str($str,$start=0,$length=80){
    $cur_len = 0; //人掌握的字符串长度
    $all_len = strlen($str); //机器理解字符串长度
    if($length > $all_len)
    {
         return $str;
    }
    for($i = 0;$i < $all_len;)
    {
         if($cur_len == $start)
         {
             break;
         }
         if (ord($str[$i]) > 127)
         {
             $i += 3;
         }else{
             $i += 1;
         }
         $cur_len ++;
    }
     $start_pos = $i;
     $temp_pos = $cur_len;
     for(;$cur_len – $temp_pos < $length;)
     {
         if($i >= $all_len)
             break;
         if (ord($str[$i]) > 127)
         {
             $i += 3;
         }else{
             $i += 1;
         }
         $cur_len ++;
     }
     $end_pos = $i;
     return substr($str,$start_pos,$end_pos);
 }
 ?>

源码下载地址

改进后我们把它分页,那样可支撑ut8与gbk等国文字符截取

 代码如下

function substrs($content, $length){
 if($length && strlen($content)>$length){
  if($db_charset!=’utf-8′){
   $retstr=”;
   for($i = 0; $i < $length – 2; $i++) {
    $retstr .= ord($content[$i]) > 127 ?
$content[$i].$content[++$i] : $content[$i];
美高梅开户网址 ,   }
   return $retstr;
  }else{
   return utf8_trim(substr($content,0,$length*3));
  }
 }
 return $content;
}

function utf8_trim($str) {
 $len = strlen($str);
 for($i=strlen($str)-1;$i>=0;$i-=1){
  $hex .= ‘ ‘.ord($str[$i]);
  $ch   = ord($str[$i]);
  if(($ch & 128)==0) return substr($str,0,$i);
  if(($ch & 192)==192)return substr($str,0,$i);
 }
 return($str.$hex);
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图