您好,欢迎访问一九零五行业门户网

WML处理---H_wml.php

h_encod = gb2312; //设置字符编码(wap页的编码) $h_wml -> h_head(); //设置头信息 $h_wml -> h_nocah(); //无缓存(是否缓存)需要缓存则不需要写该行 $h_wml -> h_card(cd1,叶绿辉香); //设定card标签 $h_wml -> h_img(image/logo.wbmp,logo); //设定图片(图片路径,注释) $h_wml -> h_br(); //换行 $h_wml -> h_link(index.php,去首页); //超链接(连接地址,文字) $h_wml -> h_str( ); //空格 $h_wml -> h_br(); //换行 $h_wml -> h_str(qq:273642232;email:yin273642232@163.com); //字符串 $h_wml -> h_disp(); //显示*************************************///start classclass h_wml{ public $h_debug = false; public $h_desce; //描述 public $h_root_dir; //文件地址路径 public $h_str; //字符 public $h_encod; //字符编码 public $h_bqi=0; public $h_gbary; public function __construct(){ //当实例化一个对象的时候,这个对象的这个方法首先被调用 return ''; } public function __destruct(){ //当删除一个对象或对象操作终止的时候,调用该方法 return ''; } public function __get($key){ //当试图读取一个并不存在的属性的时候被调用 return '['.$key.'] variable not find'; } public function __set($key,$val){ //当试图向一个并不存在的属性写入值的时候被调用 return '['.$key.'] variable not find'; } public function __call($key,$args){ //当试图调用一个对象并不存在的方法时,调用该方法 return '['.$key.'] function not find'; } public function __tostring(){ //当打印一个对象的时候被调用 return $this -> h_desce(); } public function __clone(){ //当对象被克隆时,被调用 return clone; } public function h_desce(){ //返回描述 $this -> h_desce .= '类名:h_wml-wml处理;'; $this -> h_desce .= '函数:h_head(),返回:这是wml头部,参数:无;'; $this -> h_desce .= '函数:h_endbq($val),返回:记录结束标签,参数:$val-被记录的标签;'; $this -> h_desce .= '函数:h_card($id,$title),返回:设置卡片,参数:$id-该卡片的id.$title-该卡片的title;'; $this -> h_desce .= '函数:h_nocah(),返回:设置缓存,参数:无;'; $this -> h_desce .= '函数:h_p($str,$align=left),返回:设置一行,参数:$str-改行字符串.$align-显示模式(默认居左 left);'; $this -> h_desce .= '函数:h_link($link,$str),返回:设置连接,参数:$link-连接地址.$str连接字符;'; $this -> h_desce .= '函数:h_img($src,$alt),返回:设置图片,参数:$src-图片文件路径.$alt-图片描述;'; $this -> h_desce .= '函数:h_input($name,$type=text,$format=,$maxlength=10,$emptyok=false),返回:设置输入框,参数:$name-名字.$type-类型(默认text).$format-格式,$maxlength-最大长度.$emptyok-是否记录(默认不记录);'; $this -> h_desce .= '函数:h_br(),返回:设置换行,参数:无;'; $this -> h_desce .= '函数:h_str($str),返回:设置字符,参数:$str-字符串;'; $this -> h_desce .= '函数:h_disp(),返回:输出信息(wml内容),参数:无;'; return $this -> h_desce; } public function h_head(){ //设置头信息 $this -> h_gbary=; $this -> h_bqi = 0; $h_head = header('content-type:text/vnd.wap.wml'.($this -> h_encod == '' ? '' : ';charset='.$this -> h_encod)); $h_head .= \n; $h_head .= h_encod == '' ? '' : ' encoding='.$this -> h_encod.'').?>; $h_head .= \n; $h_head .= ''; $h_head .= \n; $h_head .= ''; $h_head .= \n; $this -> h_endbq(''); $this -> h_str = $h_head; return true; } public function h_endbq($val){ $this -> h_gbary[$this -> h_bqi] = $val; ++$this -> h_bqi; return true; } public function h_card($id,$title){ //设置卡片 $h_card = ; $h_card .= \n; $this -> h_endbq(''); $this -> h_str .= $h_card; return true; } public function h_nocah(){ //设置缓存 $h_nocah = ; $h_nocah .= \n; $this -> h_str .= $h_nocah; return true; } public function h_p($str,$align=left){ //设置一行 $h_p = .$str.'
'; $h_p .= \n; $this -> h_str .= $h_p; return true; } public function h_link($link,$str){ //设置连接 $h_link = .$str.; $h_link .= \n; $this -> h_str .= $h_link; return true; } public function h_img($src,$alt){ //设置图片 $h_img = ''; $h_img .= \n; $this -> h_str .= $h_img; return true; } public function h_input($name,$type=text,$format=,$maxlength=10,$emptyok=false){ //设置输入框 $h_input = ''; $h_input .= \n; $this -> h_str .= $h_img; return true; } public function h_br(){ //设置换行 $this -> h_str .= '
'; return true; } public function h_str($str){ //设置字符 $this -> h_str .= $str; return true; } public function h_disp(){ //输出信息 while($this -> h_bqi > 0){ $val .= \n.$this -> h_gbary[$this -> h_bqi -1 ]; --$this -> h_bqi; } echo $this -> h_str.$val; return true; } public function text2wml($content){ // 将 wml 变量前缀$转义 $content = str_replace('$', '$$', $content); // 转换特殊字符,并将 windows/dos 换行符(\r\n)转化为 unix 换行符(\n) $content = str_replace(\r\n, \n, htmlspecialchars($content)); // 通过换行符来将各行分开进行处理(过滤空行) $content = explode(\n, $content); for ($i = 0; $i < count($content); $i++) { // 过滤首尾空格 $content[$i] = trim($content[$i]); // 如果去掉全角空格为空行,则设为空行,否则不对全角空格过滤。 if (str_replace( , , $content[$i]) == ) $content[$i] = ; } //合并各行,转化为 wml,并过滤掉空行 $content = str_replace(
\n, , implode(
\n, $content).\n); return $content; } public function html2wml($content,$h_p=,$h_str=){ // 过滤掉样式表和脚本 $content = preg_replace(/