$weburl="http://127.0.0.1";
function fcontents( $url ) 

if ( extension_loaded( 'curl' ) ) 

$ch = curl_init( trim( $url ) ); 
curl_setopt( $ch,CURLOPT_HEADER,0 ); 
curl_setopt( $ch,CURLOPT_RETURNTRANSFER,1 ); 
$content = curl_exec( $ch ); 
curl_close( $ch ); 
return $content; 

$text = "你好"; function strip_selected_tags($text){    
  $swap_arr = array( );
  $content = fcontents( "".$weburl."/inc/words.txt" );
  $content = str_replace( "\r", "", $content );
  $content = preg_split( "/\\n/", $content, -1, PREG_SPLIT_NO_EMPTY );
  foreach ( $content as $k => $v )
  {
  if ( $k != 0 )
  {
    $str_data = explode( "→", $v );
    $swap_arr += array(
      $str_data['0']."" => $str_data['1'].""
    );
  }
  }
  $text = strtr($text,$swap_arr);  
  
     return   $text;   
} echo strip_selected_tags($text);

解决方案 »

  1.   

    $weburl="http://127.0.0.1";
    function fcontents($url){
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
    $fcontents = curl_exec($ch);
    //$fcontents =iconv("gb2312", "UTF-8",curl_exec($ch));
        return $fcontents;
    }
    $swap_tag = array( ); 
    $content = fcontents( ''.$weburl.'/inc/words.txt' ); 
    $content = str_replace( "\r",'',$content ); 
    $content = preg_split( "/\\n/",$content,-1,PREG_SPLIT_NO_EMPTY ); 
    foreach ( $content as $k =>$v ) 

    if ( $k != 0 ) 

    $str_data = explode( '→',$v ); 
    $swap_tag += array( 
    $str_data['0'].'' =>$str_data['1'].'' 
    ); 

    } $xyask ='怎样';
    $xyask=strtr($xyask,$swap_tag);echo $xyask;