好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

5、PHP替换标签字符

有时我们需要将字符串、模板标签替换成指定的内容,可以用到下面的函数:

  1   function  stringParser( $string , $replacer  ){ 
   2  
  3       $result  =  str_replace ( array_keys ( $replacer ),  array_values ( $replacer ), $string  ); 
   4  
  5       return   $result  ; 
   6  
  7   }
   8  
  9   //  使用方法如下 
 10  
 11   $string  = ' The {b}anchor text{/b} is the {b}actual word{/b} or words used 
  12  {br}to describe the link {br}itself' ; 
  13  
 14   $replace_array  =  array ('{b}' => '<b>','{/b}' => '</b>','{br}' => '<br >' ); 
  15  
 16   
 17  
 18   echo  stringParser( $string , $replace_array );</br >


查看更多关于5、PHP替换标签字符的详细内容...

  阅读:44次