Example #1
0
 function __construct($database, $location = "./")
 {
     $this->dbName = $database;
     $this->path = $location;
     if (!($this->path = NWPathComplete($this->path))) {
         return false;
     }
     if (!($fileName = NWFileExists($this->dbName, "nwdb", $this->path))) {
         if (!$this->NWDBCreate()) {
             NWWriteLog("Creation of " . $this->dbName . " failed.");
             return false;
         }
     }
     $this->fileName = NWFileExists($this->dbName, "nwdb", $this->path);
     $this->dataBase = new \DOMDocument();
     $this->dataBase->preserveWhiteSpace = false;
     $this->dataBase->formatOutput = true;
     $this->dataBase->load($this->fileName);
 }
function NWReadFileToLine($file, $lineEnd = 0, $lineStart = 0, $path = "./")
{
    $lineEnd = $lineEnd - 1;
    if (!($path = NWPathComplete($path))) {
        if (DEBUG) {
            NWWriteLog("Couldn't resolve path.");
        }
        return false;
    }
    $linesArr = file($path . $file);
    $maxLines = count($linesArr);
    if ($lineEnd <= 0 or $lineEnd < $lineStart) {
        $lineEnd = $maxLines;
        if (DEBUG) {
            NWWriteLog("Line parameters are not as expected #1. Modifying.");
        }
    }
    if ($lineEnd > $maxLines) {
        $lineEnd = $maxLines;
        if (DEBUG) {
            NWWriteLog("Line parameters are not as expected #2 (End: {$linesEnd} but Max: {$maxLines}). Modifying.");
        }
    }
    if ($lineStart > $maxLines) {
        $lineEnd = $lineEnd - 1;
        if (DEBUG) {
            NWWriteLog("Line parameters are not as expected #2. Modifying.");
        }
    }
    for ($i = $lineStart; $i <= $lineEnd; $i++) {
        $returnArray[] = $linesArr[$i];
    }
    return implode("", $returnArray);
}