Home > php教程 > PHP源码 > HTML页面指定符号,使该符号内的内容当做PHP代码。

HTML页面指定符号,使该符号内的内容当做PHP代码。

PHP中文网
Release: 2016-05-25 17:09:17
Original
1018 people have browsed it

跳至

<?php
	
   /** 
    * 把一个指定的HTML页面显示。如果有页面中有放PHP代码的地方就执行PHP代码。
    * 放置PHP代码的地方都有$fuhao1和$fuhao2
   * @param unknown_type $filename
   * @param unknown_type $fuhao1
   * @param unknown_type $fuhao2
   */
  function display2($filename,$fuhao1,$fuhao2,$xiandingarr){
  	$filestr=file_get_contents($filename);
  	$ennable=false;
  	$tmpstr=null;
  	$isxianding=false;
  	$biaojis=xiandingByArr($filestr, $xiandingarr);
    for ($i=0;$i<strlen($filestr);$i++){
    	$j=0;
    	foreach ($biaojis as $biaoji)
    	 {
    	 	 if($biaoji[0]=$i){
    	        $j=1;
    	 	 	$isxianding=true;
    	 	 }
    	 }
    	 if($j==0){
    	 	$isxianding=false;
    	 }
    	 if($isxianding){
    	 	$ennable=false;
    	 }
    	else if($filestr[$i]==$fuhao1){
    		$ennable=true;
    	}
    	else if($filestr[$i]==$fuhao2){
    		if($ennable){
    		  	
    			$functioncode=substr($tmpstr, 1);
    			$functionname=create_function("", "$functioncode;");
    			$functionname();
    			$ennable=false;
    			$tmpstr=null;
    			continue;
    		}
    	}
    	
    	if($ennable){
    		$tmpstr.=$filestr[$i];
    	}
    	else{
    		echo $filestr[$i];
    	}
    }
    echo $tmpstr;
  }
 /**
  * 过滤指定的字符。使之不当做PHP代码
  * @param unknown_type $str
  * @param unknown_type $xianding1
  * @param unknown_type $xianding2
  * @return multitype:
  */
function xianding($str,$xianding1,$xianding2){
	$pos=-1;
	$resultarr=array();
	while(!(($pos=strpos($str, $xianding1,$pos+1))===false)){
		$tmppos=$pos;
		if(!(($pos=strpos($str, $xianding2,$pos+1))===false)){
			echo $pos;
			$tmparr=array($tmppos,$pos+strlen($xianding2));
			array_push($resultarr, $tmparr);
		}
		else{
			break;
		}
	}
	return $resultarr;
}
/**
 * 根据数组中的数据来过滤,使之不当做PHP代码
 * @param unknown_type $str
 * @param unknown_type $xiandingarr
 * @return multitype:
 */
function xiandingByArr($str,$xiandingarr){
	$pos=-1;
	$resultarr=array();
 foreach ($xiandingarr as $xian){
 	while(!(($pos=strpos($str, $xian[0],$pos+1))===false)){
 		$tmppos=$pos;
 		if(!(($pos=strpos($str, $xian[1],$pos+1))===false)){
 			$tmparr=array($tmppos,$pos+strlen($xian[1]));
 			array_push($resultarr, $tmparr);
 		}
 		else{
 			break;
 		}
 	}
 }
	return $resultarr;
}
$filestr=file_get_contents("include.html");
$xianarr=array(
		 array(""), array("") ); print_r(xiandingByArr($filestr, $xianarr)); display2("include.html", "{", "}",$xianarr); ?>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template