php ubb代码转换函数

 更新时间:2016年11月25日 15:13  点击:1735
php ubb代码转换函数


<?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>&nbsp;&nbsp;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">')"
  );

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

  $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));

                return $string;
}

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

function cuturl($url) {
 $length = 65;
 $urllink = "<a href="".(substr(strtolower($url), 0, 4) == 'www.' ? "http://$url" : $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;
}
?>

php 文本转HTML与获取IP函数

/**
 * 文本转HTML
 *
 * @param string $txt;
 * return string;
 */
function Text2Html($txt){
 $txt = str_replace("  "," ",$txt);
 $txt = str_replace("<","&lt;",$txt);
 $txt = str_replace(">","&gt;",$txt);
 $txt = preg_replace("/[rn]{1,}/isU","<br/>rn",$txt);
 return $txt;
}

/**
 * 获得IP
 * return string;
 */
function GetIP(){
 if(!empty($_SERVER["HTTP_CLIENT_IP"])) { $cip = $_SERVER["HTTP_CLIENT_IP"]; }
 else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; }
 else if(!empty($_SERVER["REMOTE_ADDR"])) { $cip = $_SERVER["REMOTE_ADDR"]; }
 else $cip = "";
 preg_match("/[d.]{7,15}/", $cip, $cips);
 $cip = $cips[0] ? $cips[0] : 'unknown';
 unset($cips);
 return $cip;
}

php 生成验证码源码


session_start();

$enablegd = 1;
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
 if(!function_exists($func))
 {
  $enablegd = 0;
  break;
 }
}

ob_clean();

if($enablegd)
{
 //create captcha
 $consts = 'cdfgkmnpqrstwxyz23456';
 $vowels = 'aek23456789';
 for ($x = 0; $x < 6; $x++)
 {
  $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
  $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
 }
 $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
 $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
 //set up image, the first number is the width and the second is the height
 $imageX = strlen($radomstring)*8; //the image width
 $imageY = 20;      //the image height
 $im = imagecreatetruecolor($imageX,$imageY);

 //creates two variables to store color
 $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
 $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
         imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
         imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
         imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
 $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
 $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
 $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80);

 //fill image with bgcolor
 imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
 //writes string
 imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[0]);
 imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
 imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[2]);
 imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/arial.ttf', $string[3]);
 
 //strikethrough

 $border = imagecolorallocate($im, 133, 153, 193);
 //imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
 imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

 $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
 for ($i=0;$i<80;$i++)
 {
  imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
 }
 //random shapes
 for ($x=0; $x<9;$x++)
 {
  if(mt_rand(0,$x)%2==0)
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
  }
  else
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
  }
 }
 //output to browser
    header("content-type:image/pngrn");
 imagepng($im);
 imagedestroy($im);
}
else
{
 $files = glob(PHPCMS_ROOT.'images/checkcode/*.jpg');
 if(!is_array($files)) exit($LANG['please_check_dir_images_checkcode']);

 $checkcodefile = $files[rand(0, count($files)-1)];
 $_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4);

 header("content-type:image/jpegrn");
 include $checkcodefile;
}

php简单文件下载过滤判断函数

if(strpos($fileurl, ':/'))//远程文件
{
 header("Location: $fileurl");
}
else//本地文件
{
 if($d == 0)
 {
  header("Location: ".SITE_URL.$fileurl);
 }
 else
 {
  $fileurl = file_exists($fileurl) ? stripslashes($fileurl) : PHPCMS_ROOT.$fileurl;//此处可能为物理路径
  $filename = basename($fileurl);
  if(preg_match("/^([sS]*?)([x81-xfe][x40-xfe])([sS]*?)/", $fileurl))//处理中文文件
  {
   $filename = str_replace(array("%5C", "%2F", "%3A"), array("\", "/", ":"), urlencode($fileurl));
   $filename = urldecode(basename($filename));
  }
  file_down($fileurl, $filename);
 }
}

php imagecreate图片生成代码


if(isset($gd) && $gd==1 && $txt)
{
 header ("Content-type: image/png");
 $txt = urldecode(phpcms_auth($txt, 'DECODE', AUTH_KEY));
 $imageX = strlen($txt)*9;
 $im = @imagecreate ($imageX, 16) or die ("Cannot Initialize new GD image stream");
 $bgColor = ImageColorAllocate($im,255,255,255);
 $white=imagecolorallocate($im,234,185,95);
 $font_color=imagecolorallocate($im,0x00,0x00,0x00);
 
 $fontfile = PHPCMS_ROOT."include/fonts/simfang.ttf";
 if(file_exists($fontfile) && !preg_match('/([a-z0-9@.])/',$txt))
 {
  $txt = iconv("GB2312","UTF-8",$txt);
  ImageTTFText($im, 10, 0, 0, 12, $font_color, $fontfile, $txt);
 }
 else
 {
  $fonttype = intval($fonttype);
  imagestring ($im, $fonttype, 0, 0,$txt, $font_color);
 }
 imagepng ($im);
 imagedestroy ($im);
}

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • 使用PHP+JavaScript将HTML页面转换为图片的实例分享

    这篇文章主要介绍了使用PHP+JavaScript将HTML元素转换为图片的实例分享,文后结果的截图只能体现出替换的字体,也不能说将静态页面转为图片可以加快加载,只是这种做法比较interesting XD需要的朋友可以参考下...2016-04-19
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • 在数据库里将毫秒转换成date格式的方法

    在开发过程中,我们经常会将日期时间的毫秒数存放到数据库,但是它对应的时间看起来就十分不方便,我们可以使用一些函数将毫秒转换成date格式。 一、 在MySQL中,有内置的函数from_unixtime()来做相应的转换,使用如下: 复制...2014-05-31
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • 美图秀秀把普通照片快速转换成卡通效果教程

    今天小编在这里就来给美图秀秀的这一款软件的使用者们来说下把普通照片快速转换成卡通效果的教程,各位想知道具体制作步骤的使用者们,那么下面就快阿里跟着小编一起看一...2016-09-14
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • Javascript类型转换的规则实例解析

    这篇文章主要介绍了Javascript类型转换的规则实例解析,涉及到javascript类型转换相关知识,对本文感兴趣的朋友一起学习吧...2016-02-27
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20