handling php code
morning. I am wanting to take all segments of php code out of a file located on my local server. Problem is i dont seem to be getting anywhere, no php errors just browser errors.
$file_contents = "<xmp>".file_get_contents("../www.cms.actwebdesigns.co.uk开发者_Go百科2/pageIncludes/instalation/selectMainPages.php")."</xmp>";
if(preg_match_all("#<\?php((?!\?>).)*#is", $file_contents, $matches))
{
foreach($matches[0] as $phpCode)
{
$code = "<xmp>".$phpCode."\n?></xmp>";
}
}
echo "dsds";
?>
could someone please point me in the right direction?
working with this:
$file_contents = token_get_all(file_get_contents("../www.cms.actwebdesigns.co.uk2/logged.php"));
$start=0;
$end=0;
$segmentArray = array();
foreach($file_contents as $key => $token)
{
$tokenName = token_name($key);
if($start==0 && $end==0 && $tokenName=="T_OPEN_TAG")
{
$start=1;
}
if(start==1 && $end==0 && $tokenName!="T_CLOSE_TAG")
{
$entryNo = count($segmentArray);
$segmentArray[$entryNo][] = $token;
}
if($tokenName=="T_CLOSE_TAG")
{
$start=0;
}
}
You might want to tokenize the PHP script using the Tokenizer extension:
http://php.net/manual/en/book.tokenizer.php
The extensions is built into PHP since PHP v4.3.0.
$tokens = token_get_all(file_get_contents($file));
http://www.php.net/manual/en/function.token-get-all.php
Not sure how to use this. Puts all code into an array. For me to use it wouldn't i have to implode it or something then im back to square one?
精彩评论