Example #1
0
    //returns 1 if valid number (only numeric string), 0 if not
    //	if (ereg('^[[:digit:]]+$', $strnum)) {
    if (ereg('^0|[1-9][0-9]*|[1-9][0-9]*[.][0-9]{1,2}$', $strnum)) {
        return 1;
    } else {
        return 0;
    }
}
function func_check_isnumberdot($var)
{
    for ($i = 0; $i < strlen($var); $i++) {
        $ascii_code = ord($var[$i]);
        if ($ascii_code >= 49 && $ascii_code <= 57 || $ascii_code == 46) {
            continue;
        } else {
            return 0;
        }
    }
    return true;
}
$export_value = 6576578.9789;
print "Check number : " . func_check_isnumber(552083);
if (!func_check_isnumberdot($export_value)) {
    $export_value = "*" . $export_value;
    print "<br>Abish checking :" . $export_value;
}
print "<br>Exp val : " . $export_value;
print "<br>Is number of : " . func_check_isnumberdot('6576578.9789');
print "<br> val" . ord('.');
$ans = split(",", $export_value);
print $ans[0];
Example #2
0
function func_export_details($qrt_select_details, $cnn_cs, $exportlist, $trans_entry)
{
    $i = 0;
    $data = "";
    $value = "";
    $header = "";
    if (!($qrt_select_run = mysql_query($qrt_select_details, $cnn_cs))) {
        dieLog(mysql_errno() . ": " . mysql_error() . "<BR>");
    } else {
        if (mysql_num_rows($qrt_select_run) == 0) {
            $msgtodisplay = "No transactions for this period";
        }
    }
    if ($exportlist) {
        for ($i_loop = 0; $i_loop < count($exportlist); $i_loop++) {
            $export_select_list = $exportlist[$i_loop];
            $list_header_val = func_set_header($exportlist[$i_loop], $trans_entry);
            if ($header == "") {
                $header = '"' . "{$list_header_val}" . '"';
            } else {
                $header = "{$header} ," . '"' . "{$list_header_val}" . '"';
            }
        }
        $header = "{$header} \t";
    }
    while ($show_select_val = mysql_fetch_array($qrt_select_run)) {
        $export_value = "";
        $value1 = "";
        if ($exportlist) {
            for ($i_loop = 0; $i_loop < count($exportlist); $i_loop++) {
                $export_value = $show_select_val["{$exportlist[$i_loop]}"];
                if ($exportlist[$i_loop] == "userId") {
                    $qrt_select_company = "Select companyname from cs_companydetails where userid = {$export_value}";
                    $export_value = funcGetValueByQuery($qrt_select_company, $cnn_cs);
                }
                if ($export_value == "PE" || $export_value == "P") {
                    $export_value = "Pending";
                } elseif ($export_value == "PA") {
                    $export_value = "Pass";
                } elseif ($export_value == "NP") {
                    $export_value = "Non Pass";
                } elseif ($export_value == "A") {
                    $export_value = "Approved";
                } elseif ($export_value == "D") {
                    $export_value = "Declined";
                } elseif ($export_value == "Y") {
                    $export_value = "Cancelled";
                } elseif ($export_value == "N") {
                    $export_value = "Not Cancelled";
                } elseif ($export_value == "C") {
                    $export_value = "Check";
                } elseif ($export_value == "H") {
                    $export_value = "Credit Card";
                }
                // Checking whether the value is number or not, is an ascii check.
                if (func_check_isnumberdot($export_value)) {
                    $export_value = "^ " . $export_value;
                }
                $export_value = str_replace(",", "", $export_value);
                if ($value1 == "") {
                    $value1 = '"' . $export_value . '"';
                } else {
                    $value1 = $value1 . "," . '"' . $export_value . '"';
                }
            }
        }
        $value = $value1 . '"' . "\t";
        if (!isset($value) || $value == "") {
            $value = "\t";
        } else {
            $value = '"' . $value . '"' . "\t";
        }
        $line = '"' . $value;
        $data .= trim($line) . "\n";
    }
    $data = str_replace("\r", "", $data);
    $data = str_replace('"', "", $data);
    if ($data == "") {
        $data = "\n No matching records found\n";
    }
    # this line is needed because returns embedded in the data have "\r"
    # and this looks like a "box character" in Excel
    $data = str_replace("\t", "", $data);
    $header = str_replace("\t", "", $header);
    $str_current_path = "csv/report.csv";
    //	print $str_current_path;
    $create_file = fopen($str_current_path, 'w');
    //	print $create_file;
    $file_content = $header . "\n" . $data;
    fwrite($create_file, $file_content);
    fclose($create_file);
    # Nice to let someone know that the search came up empty.
    # Otherwise only the column name headers will be output to Excel.
    # This line will stream the file to the user rather than spray it across the screen
    //		header("Content-type: application/octet-stream");
    //		header("Content-Disposition: attachment; filename=excelfile.htm");
    // header("Pragma: no-cache");
    // header("Expires: 0");
    // echo $header."\n".$data;
    if (!($file = fopen("csv/report.csv", "r"))) {
        print "Can not open file";
        exit;
    }
    /*	$content = fread($file, filesize("csv/excelfile.htm"));
    		$content = explode("\r\n", $content);
    		fclose($file);
    		$file_content = "";
    		for($i=0;$i<count($content);$i++)
    		{
    			$file_content .= $content[$i];
    		}
    		print($file_content);
    		if( file_exists($str_current_path)) {
    			//unlink($str_current_path);
    		} */
}