PHP – Remove Allowable Whitespace


$newSource = '';
foreach (token_get_all($source) as $i => $token) {
    if (!is_array($token)) {
        $newSource .= $token;
    }

    if ($token[0] == T_WHITESPACE) {
        if (   isset($tokens[$i - 1])      && isset($tokens[$i + 1])
            && is_array($tokens[$i - 1])   && is_array($tokens[$i + 1])
            && isLabel($tokens[$i - 1][1]) && isLabel($tokens[$i + 1][1])
        ) {
            $newSource .= ' ';
        }
    } else {
        $newSource .= $token[1];
    }
}

function isLabel($str) {
    return preg_match('~^[a-zA-Z0-9_\x7f-\xff]+$~', $str);
}


source:
http://stackoverflow.com/questions/4908588/removing-allowable-whitespace-in-php-using-parser-tokens

PHP – Remove Comments from PHP File


$fileStr = file_get_contents('path/to/file');
$newStr  = '';

$commentTokens = array(T_COMMENT);

if (defined('T_DOC_COMMENT'))
    $commentTokens[] = T_DOC_COMMENT; // PHP 5
if (defined('T_ML_COMMENT'))
    $commentTokens[] = T_ML_COMMENT;  // PHP 4

$tokens = token_get_all($fileStr);

foreach ($tokens as $token) {    
    if (is_array($token)) {
        if (in_array($token[0], $commentTokens))
            continue;

        $token = $token[1];
    }

    $newStr .= $token;
}

echo $newStr;


source:
http://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code

PHP, Crystal Report, MS SQL Server


PHP 5.1.6, MSSQL2005 and Crystal Report Server XI RL2

<?php
//- Variables – for your RPT and PDF
echo “Print Report Test”;
$my_report = “D:\\Folder1\\SubFolder1\\Report.rpt”; //
rpt source file
$my_pdf = “D:\\Folder1\\SubFolder1\\Report.pdf”; // RPT export to pdf file
//-Create new COM object-depends on your Crystal Report version
$ObjectFactory= new COM(“CrystalReports115.ObjectFactory.1”) or die (“Error on load”); // call COM port
$crapp = $ObjectFactory-> CreateObject(“CrystalDesignRunTime.Application”); // create an instance for Crystal
$creport = $crapp->OpenReport($my_report, 1); // call rpt report

// to refresh data before

//- Set database logon info – must have
$creport->Database->Tables(1)->SetLogOnInfo(“servername”, “DBname”, “user”, “password”);

//- field prompt or else report will hang – to get through
$creport->EnableParameterPrompting = 0;

//- DiscardSavedData – to refresh then read records
$creport->DiscardSavedData;
$creport->ReadRecords();
//export to PDF process
$creport->ExportOptions->DiskFileName=$my_pdf; //export to pdf
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; // export to file
$creport->ExportOptions->FormatType=31; // PDF type
$creport->Export(false);

//—— Release the variables ——
$creport = null;
$crapp = null;
$ObjectFactory = null;

//—— Embed the report in the webpage ——
print “
?>

 

source:

http://php.net/manual/en/class.com.php