0

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.uk2/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?

2
  • 3
    Baaaaad question. Consider taking some time to explain cause, effect, errors, and intent. Baa. Commented Oct 18, 2009 at 4:24
  • for the past 14months i've been working on a plug n play CMS (takes 45secs to install and your away!) but i want to go up a knotch by installing to a pre made php website. So i need to try and separate data. error This web page is not available. The web page at null might be temporarily down or it may have moved permanently to a new web address. More information on this error Below is the original error message Error 101 (net::ERR_CONNECTION_RESET): Unknown error. Commented Oct 18, 2009 at 4:31

3 Answers 3

2

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;   
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Running into a problem. Alot of the token names are returning UNKNOWN. any one know why?
1

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

2 Comments

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?
you can loop through and remove all those which are not PHP code.
0

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?

1 Comment

This is either a comment on an answer or you should just edit your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.