function saveSchedule() { //Funktion som läser datan från GET-meddelandet och gör det redo för att läggas in i databasen. $array = json_decode($_REQUEST["array"]); $name = $_REQUEST["name"]; if (preg_match("/[a-zA-ZåäöÅÄÖ0-9]+/", $name)) { if (!empty($array)) { $temp = ""; $time = ""; for ($i = 0; $i < count($array); $i++) { $temp .= "/" . $array[$i][0]; $time .= "/" . $array[$i][1]; } if (preg_match("/[0-9]+/", $temp)) { if (preg_match("/[0-9]+/", $time)) { writeData($name, $temp, $time); } else { echo "Time not valid"; } } else { echo "Temp not valid"; } } } else { echo "Name not valid"; } }
/** * Handle and read uploaded file * @param array - fileArray from form * @param array - postArray from form */ function handleUpload($_FILES, $_POST) { require_once "JotForm.php"; $path = mktime() . '_' . $_FILES['file']['name']; $key = $_POST['APIkey']; $form = $_POST['formID']; $jot = new JotForm($key); $error = ""; if (move_uploaded_file($_FILES['file']['tmp_name'], $path)) { $fileType = getFileType($path); $columns = array(); if ($fileType == 'csv') { if (($handle = fopen($path, "r")) !== FALSE) { if (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { foreach ($data as $title) { array_push($columns, $title); } } $error = 'File must contain at least two rows - the first represents the field titles'; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $error = ''; $result = $jot->createFormSubmissions($form, writeData($data, $columns)); } fclose($handle); } else { $error = 'Could not open file'; } } else { require_once 'Excel/reader.php'; $excel = new Spreadsheet_Excel_Reader(); $excel->read($path); if ($excel->sheets[0]['numRows'] > 1) { for ($i = 1; $i <= $excel->sheets[0]['numCols']; $i++) { $title = $excel->sheets[0]['cells'][1][$i]; array_push($columns, $title); } for ($i = 2; $i <= $excel->sheets[0]['numRows']; $i++) { $data = array(); for ($j = 1; $j <= $excel->sheets[0]['numCols']; $j++) { array_push($data, $excel->sheets[0]['cells'][$i][$j]); } $jot->createFormSubmissions($form, writeData($data, $columns)); } } else { $error = 'File must contain at least two rows - the first represents the field titles'; } } } else { $error = 'No File Found'; } if (strlen($error) > 0) { return $error; } else { return 'none'; } }
function main() { global $argc, $argv; if (sizeof($argv) == 1) { echo "Please specify a file to write to. \n"; exit(1); } writeData($argv[1]); exit(0); }
function updateDatosPer($userId, $email, $telefono, $direccion, $fecha) { $query = "update datos_per set bitnet='" . $email . "', telefono='" . $telefono . "', direccion= '" . $direccion . "', fec_nacimi='" . $fecha . "' where cedula = '" . $userId . "'"; return writeData($query); }
usleep(rand(1, 10000)); } $retries += 1; } while (!flock($fp, LOCK_EX) and $retries <= $max_retries); if ($retries == $max_retries) { return false; } fwrite($fp, $data . "\n"); flock($fp, LOCK_UN); fclose($fp); return true; } error_reporting(0); try { $content = file_get_contents("php://input"); $error = error_get_last(); if ($error['message']) { throw new Exception($error['message']); } if ($content != "") { if (writeData("experiment1_result.txt", "a", $content)) { echo "Success."; // echo "Fail. Please submit one more time."; } else { echo "Fail. Please submit one more time."; } } } catch (Exception $e) { // exit('禁止访问'); echo $e->getMessage(); }
/** * Parses JSON object for tweets, gets sentiment object & writes to file with date * @param array of JSON data, number of tweets to analyze */ function parseData($arr, $num) { global $path; $count = 0; $flag = file_exists($path); $res = array(); //for debug $ind = 0; foreach ($arr as $tweet) { if ($flag == true) { $flag = false; continue; } $date = getTweetDate($tweet); $id = getTweetID($tweet); $str = getTweetText($tweet); $str = cleanTweet($str); if (strlen($str) < 5) { continue; } //using alchamy $sentiment = getTweetSentiment($str); $result = array(); $result[0] = $id; $result[1] = $date; $result[2] = $str; $result[3] = $sentiment->type; $result[4] = $sentiment->score; $resultString = getCacheString($result); writeInfo($result); writeData($resultString); $res[$ind++] = $resultString; if ($count > $num) { break; } $count++; } return $res; }
/** * 创建PHP缓存数组 * @param $array * @param $filePath * @param $return */ function createPhpArr($array, $filePath, $return = null) { if (!$array) { return false; } if (!$filePath) { return false; } if ($return == null) { $return = 'return '; } else { $return = "{$return} = "; } $str = "<?php\r\n"; $str .= $return; $str .= var_export($array, true); $str .= "\r\n?>"; if (writeData($filePath, $str)) { return true; } else { return false; } }
$smarty = new Smarty(); smarty(); //ログイン状態の判別 if (isset($_SESSION["user_id"])) { define('LOGINED', true); } else { define('LOGINED', false); } //投稿 if ($_SERVER['REQUEST_METHOD'] == "POST") { if (!isset($_POST['user']) or !isset($_POST['message']) or empty($_POST['user']) or empty($_POST['message'])) { $display_message = '文字を入力してください'; } else { $user = $_POST['user']; $message = $_POST['message']; writeData($user, $message); } } readData(); $post_data = readData(); $smarty->assign('display_message', $display_message); $smarty->assign('post_data', $post_data); $smarty->assign('ipadress', IPADRESS); function readData() { try { $db = getDb(); $stt = $db->prepare('select * from bbs_data order by no desc'); $stt->execute(); while ($row = $stt->fetch(PDO::FETCH_ASSOC)) { $post_data[] = $row;
$results2 = array(); if ($handle = opendir('./data/')) { while (false !== ($file = readdir($handle))) { $myFile = $file; if ($myFile != "." && $myFile != "..") { $fh = fopen("./data/" . $myFile, 'r'); $theData = fgets($fh); fclose($fh); if ($theData != "") { $array = json_decode($theData); foreach ($array as $key => $value) { $string1 = date('Y', $value->join); $string2 = date('Ym', $value->join); if (!isset($results[$string1])) { $results[$string1] = 0; } if (!isset($results2[$string2])) { $results2[$string2] = 0; } $results[$string1] = $results[$string1] + 1; $results2[$string2] = $results2[$string2] + 1; } } writeHTML($myFile, "./charts/" . $myFile, $array); writeBarData($results2, "./charts/" . $myFile); writeData($results, "./charts/" . $myFile); $results = array(); } } closedir($handle); }
function load_convert($filename) { $path = pathinfo($filename); global $min_count, $ms1_enable, $ms2_enable, $ms3_enable, $mzxml_enable, $out_file, $unpack_only; print $filename . "\n"; $scanned = simplexml_load_file($filename); $preIntensity = -1; $preCharge = -1; $mzLoad = array(); $count = 0; foreach ($scanned->msRun->children() as $a) { $preIntensity = -1; $preCharge = -1; $mH = 0; //print "Curr $count\n"; if ($a->getName() == 'scan') { $attrs = $a->attributes(); if ($attrs['msLevel'] == 2 && $ms2_enable) { if ($a->children()->getName() == 'precursorMz') { $b = $a->precursorMz; $battrs = $b->attributes(); if ($preIntensity == -1) { $preIntensity = $battrs['precursorIntensity']; } if ($preCharge == -1) { $preCharge = $battrs['precursorCharge']; } $mH = (double) $b * $preCharge; $mH = round($mH, 9); } } elseif ($attrs['msLevel'] == 1 && $ms1_enable) { $preIntensity = 0; $preCharge = 0; } $high = FALSE; if ($ms2_enable || $ms3_enable) { $high = TRUE; } $ms_id = (int) $attrs['num']; if ($mH > 0 && $high) { $label = $path['filename'] . "." . $ms_id . "." . $count . "." . $preCharge; } else { $label = $path['filename'] . "." . $ms_id . "." . "ms1"; } if ($a->peaks) { $base = base64_decode($a->peaks); if ($attrs['msLevel'] == 1 && $ms1_enable) { //print "Decoding MS1 peaks\n"; $mzLoad = mzxml_decode_peaks($a->peaks); } if ($attrs['msLevel'] == 2 && $ms2_enable) { //print "Decoding MS2 peaks\n"; $mzLoad = mzxml_decode_peaks($a->peaks); } if ($attrs['msLevel'] == 3 && $ms3_enable) { print "Given MS level " . $attrs['msLevel'] . "not currently supported"; } if (!empty($mzLoad) || $mzLoad == NULL) { if ($ms1_enable && $mH == 0 && $attrs['msLevel'] == 1) { //print "Unpacking MS1 scan\n"; $mzLoad = refine_ms1($mzLoad); if (!$unpack_only) { $mzLoad = deisotope($mzLoad, $preIntensity, $preCharge); } writeData($mzLoad, "ms1", $out_file . $label . ".dta", $min_count); $count++; } if ($ms2_enable && $mH > 0 && $attrs['msLevel'] == 2) { //print "Unpacking MS2 scan\n"; $mzLoad = refine($mzLoad); if (!$unpack_only) { $mzLoad = deisotope($mzLoad, $preIntensity, $preCharge); } writeData($mzLoad, $mH, $out_file . $label . ".dta", $min_count); $count++; } if ($ms3_enable && $mH > 0 && $attrs['msLevel'] == 3) { $mzLoad = refine($mzLoad); if (!$unpack_only) { $mzLoad = deisotope($mzLoad, $preIntensity, $preCharge); } writeData($mzLoad, $mH, $out_file . $label . ".ms3.dta", $min_count); $count++; } } else { print "ERROR: Peaks section could not be decoded.\n"; } } else { print "ERROR: No peaks provided in current scan element.\n"; } } } print "Number of scans reported {$count}\n"; }
function getplayers() { global $db; $players = array(); $result = $db->query('SELECT id FROM ' . $db->prefix . 'rscd_worlds ORDER BY id ASC') or error('Unable to fetch world list', __FILE__, __LINE__, $db->error()); while ($world = $db->fetch_assoc($result)) { $data = writeData(F_LIST_PLAYERS, $world['id']); if (!$data || ($delim = strpos($data, ' ')) < 0) { continue; } $id = substr($data, 0, $delim); $data = substr($data, $delim + 1); if ($id != 1) { continue; } $players = array_merge($players, extractplayers($data)); } return $players; }
if ($retries == $max_retries) { return false; } fwrite($fp, $data . "\n"); fflush($fp); flock($fp, LOCK_UN); fclose($fp); return true; } error_reporting(0); try { $content = file_get_contents("php://input"); $error = error_get_last(); if ($error['message']) { throw new Exception($error['message']); } if ($content != "") { if (writeData("../data/experiment2_result.txt", "a", $content)) { echo 1; // echo "Fail. Please submit one more time."; } else { echo 0; } } } catch (Exception $e) { // exit('禁止访问'); echo $e->getMessage(); } ?>
<?php $filename = "xab"; $dictfile = __DIR__ . '/result_' . $filename . '_listIdEmail_seri.log'; $targetfile = __DIR__ . '/result_' . $filename . '_listIds_seri.log'; function writeData($data, $filename) { file_put_contents(__DIR__ . '/result_' . $filename . '_extraemails_seri.log', serialize($data)); file_put_contents(__DIR__ . '/result_' . $filename . '_extraemails_dump.log', var_export($data, true)); } $targets = unserialize(file_get_contents($targetfile)); $dict = unserialize(file_get_contents($dictfile)); $emails = array(); foreach ($targets as $id) { if (!isset($dict[$id])) { continue; } $e = $dict[$id]; $hash = md5($e); if (!isset($emails[$hash])) { $emails[$hash] = $e; } } writeData($emails, $filename);
<?php function writeData($data) { $myfile = "f1.csv"; $fh = fopen($myfile, 'a'); if ($fh == false) { echo "Error opening file"; exit; } fwrite($fh, $data); fwrite($fh, "\n"); fclose($fh); } if ($_POST["t"] && $_POST["x"] && $_POST["y"]) { $csv = sprintf('%d, %d, %d', $_POST["t"], $_POST["x"], $_POST["y"]); writeData(str_replace('.', '', $csv)); } else { echo "Error pasring request"; exit; } ?>
$data = array(); $tmpAward = $row->AwDescription; $tmpCategory = $row->Category; $tmpAwarders = $row->AwAwarders; $curAward = $row->Category . "|" . $row->AwDescription; } if ($rowOrder->AwTeam) { $tmp = explode('|', $row->Athlete); $data[] = array($row->Rank, $row->Country, $tmp, $row->Score, $row->Gold, $row->XNine); } else { $data[] = array($row->Rank, $row->Athlete, $row->Country, $row->Score, $row->Gold, $row->XNine); } $idList[] = $row->EnId; } if (count($data) > 0) { writeData($pdf, $data, $tmpAward, $tmpCategory, $tmpAwarders, $rowOrder->AwTeam == 0 ? 1 : 0); } } } $pdf->Output(); function writeGroupHeader($pdf, $Description, $Category, $indEvent) { $pdf->SetFont($pdf->FontStd, 'B', 26); $pdf->Cell(0, 6, "Victory Ceremony - " . $Category, 0, 1, 'C', 1); $pdf->ln(5); $pdf->SetFont($pdf->FontStd, '', 12); $pdf->Cell(0, 6, "Ladies and Gentlemen the Victory Ceremony for the", 0, 1, 'L', 0); $pdf->SetFont($pdf->FontStd, 'B', 12); $pdf->Cell(0, 6, $Description ? $Description : $Category, 0, 1, 'L', 0); } function writeData($pdf, $data, $Description, $Category, $Awarders, $indEvent)
header('Content-type: text/html; charset=utf-8'); error_reporting(E_ALL ^ E_STRICT); ini_set('display_errors', 1); require_once __DIR__ . "/dbsimple/config.php"; require_once "DbSimple/Generic.php"; require_once __DIR__ . "/firephp/FirePHP.class.php"; $firePHP = FirePHP::getInstance(true); $firePHP->setEnabled(true); require_once 'functions_DbSimple.php'; require 'write_data.php'; $link = ''; if (isset($_POST['main_form_submit'])) { $db = (new DbSimple_Generic())->connect('mysqli://' . $_POST['user_name'] . ':' . $_POST['password'] . '@' . $_POST['server_name'] . '/' . $_POST['database']); $db->setErrorHandler('databaseErrorHandler'); $db->setLogger('myLogger'); writeData($_POST, 'server_data.txt'); $templine = ''; $lines = file('tables_xaver.sql'); foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1, 1) == ';') { if (!@$db->query($templine)) { $link = '<a href="index.php">Перейти на сайт</a>'; } else { $link = 'Ошибка: Данные введены неверно.'; }
function getDataForXml() { CModule::IncludeModule("iblock"); CModule::IncludeModule('catalog'); $filter["ACTIVE"] = "Y"; $filter["ACTIVE_DATE"] = "Y"; $filter["IBLOCK_ID"] = 2;//goodies $rsItems = CIBlockElement::GetList(array(), $filter, false, false, array()); $strOfferGoogle = ''; while ($obItem = $rsItems->GetNextElement()) { $arItem = $obItem->GetFields(); if (CModule::IncludeModule("catalog") && CCatalog::GetByID($arItem['IBLOCK_ID'])) { $arItem = $obItem->GetFields(); $productId = $arItem['ID']; $rsPrices = CPrice::GetByID($productId); $arItem['PROPERTIES'] = $obItem->GetProperties(); $strFile = ''; $arItem["DETAIL_PICTURE"] = (int)$arItem["DETAIL_PICTURE"]; $arItem["PREVIEW_PICTURE"] = (int)$arItem["PREVIEW_PICTURE"]; if ($arItem["DETAIL_PICTURE"] > 0 || $arItem["PREVIEW_PICTURE"] > 0) { $pictNo = ($arItem["DETAIL_PICTURE"] > 0 ? $arItem["DETAIL_PICTURE"] : $arItem["PREVIEW_PICTURE"]); if ($ar_file = CFile::GetFileArray($pictNo)) { if (substr($ar_file["SRC"], 0, 1) == "/") $strFile = "http://" . $_SERVER['SERVER_NAME'] . CHTTP::urnEncode($ar_file['SRC'], 'utf-8'); else $strFile = $ar_file["SRC"]; } } $arItem['google_PICT'] = $strFile; if (!empty($arItem["DETAIL_TEXT"])) $arItem['google_DESCR'] = google_text2xml(strip_tags(stristr($arItem["DETAIL_TEXT"], '.', true))); else $arItem['google_DESCR'] = google_text2xml(strip_tags($arItem["NAME"])); $strOfferGoogle .= "<item>\n"; $strOfferGoogle .= "<title>"; $strOfferGoogle .= $arItem['NAME']; $strOfferGoogle .= "</title>\n"; $strOfferGoogle .= "<link>"; $strOfferGoogle .= "http://".$_SERVER['SERVER_NAME'].$arItem['DETAIL_PAGE_URL']; $strOfferGoogle .= "</link>\n"; $strOfferGoogle .= "<description>"; $strOfferGoogle .= $arItem['google_DESCR']; $strOfferGoogle .= "</description>\n"; $strOfferGoogle .= "<g:image_link>"; $strOfferGoogle .= $strFile; $strOfferGoogle .= "</g:image_link>\n"; $strOfferGoogle .= "<g:price>"; $strOfferGoogle .= $rsPrices['PRICE']; $strOfferGoogle .= "</g:price>\n"; $strOfferGoogle .= "<g:condition>"; $strOfferGoogle .= "новый"; $strOfferGoogle .= "</g:condition>\n"; $strOfferGoogle .= "<g:id>"; $strOfferGoogle .= $arItem['CODE']; $strOfferGoogle .= "</g:id>\n"; $strOfferGoogle .= "</item>\n"; //etc etc } else { continue; } } writeData($strOfferGoogle); }
function parse_property($document) { $properties = $document->find(PROPERTY_FINDER); echo "FOUND " . count($properties) . " PROPERTIES\n"; foreach ($properties as $property) { $property_data = array(); $main_link = $property->find(MAIN_LINK_FINDER, 0); $property_data['zip'] = regex(ZIPCODE_REGEX, $main_link->href); $property_data['address'] = $main_link->plaintext; echo "FOUND: {$property_data['address']}\n"; $property_data['price'] = str_replace(array('$', ','), '', $property->find(SALE_PRICE_FINDER, 0)->plaintext); $data_table = $property->find(DATA_TABLE_FINDER, 0)->plaintext; $data_table2 = $property->find(DATA2_TABLE_FINDER, 0)->plaintext; $value = regex(BEDROOM_REGEX, $data_table); $property_data['bed'] = $value == '--' ? 0 : $value + 0; $value = regex(BATHROOM_REGEX, $data_table); $property_data['bath'] = $value == '--' ? 0 : $value + 0; $value = regex(SQUAREFOOT_REGEX, $data_table); $property_data['sqft'] = $value == '--' ? 0 : str_replace(',', '', $value) + 0; $value = regex(LOTSIZE_REGEX, $data_table); $property_data['lot'] = $value == '--' ? 0 : str_replace(',', '', $value) + 0; $value = regex(LISTED_REGEX, $data_table2) + 0; $property_data['listed'] = date('Y-m-d', strtotime("{$value} days ago")); $value = regex(BUILT_REGEX, $data_table2); $property_data['built'] = $value == '--' ? '' : $value; $value = regex(PROP_TYPE_REGEX, $data_table2); $property_data['type'] = $value; $property_data['res'] = FALSE; if ($property_data['bed'] != 0 && $property_data['sqft'] != 0) { $property_data['res'] = TRUE; } writeData($property_data); } }
<p>掲示板</p> <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?> "> <input type="text" name="personal_name"><br><br> <textarea name="contents" rows="8" cols="40"> </textarea><br><br> <input type="submit" name="btn1" value="投稿する"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { writeData(); } function writeData() { $personal_name = $_POST['personal_name']; $contents = $_POST['contents']; $contents = nl2br($contents); $data = "<hr>\r\n"; $data = $data . "<p>投稿者:" . $personal_name . "</p>\r\n"; $data = $data . "<p>内容:</p>\r\n"; $data = $data . "<p>" . $contents . "</p>\r\n"; $keijban_file = 'keijiban.txt'; $fp = fopen($keijban_file, 'ab'); if ($fp) { if (flock($fp, LOCK_EX)) { if (fwrite($fp, $data) === FALSE) {
} if ($pos = getStartDeliveryText($line)) { $pos_end = getMsgidText($line); $failureMsgId = getFailureIdFromLine($line, $pos, $pos_end); $email = detectEmailFromStr($line); if ($failureMsgId && $email) { if (!isset($lstMsgIdToEmail[$failureMsgId])) { $lstMsgIdToEmail[$failureMsgId] = $email; } } } } writeData($lines, $filename . '_lines'); writeData($emails, $filename . '_emails'); writeData($failureMsgIds, $filename . '_listIds'); writeData($lstMsgIdToEmail, $filename . '_listIdEmail'); // echo '<h1>MAILBOX ERROR: EMAILS</h1>'; // echo '<pre>',var_dump($emails),'</pre>'; // echo '<h1>MAILBOX ERROR: FAILED IDS</h1>'; // echo '<pre>',var_dump($failureMsgIds),'</pre>'; // echo '<h1>MAILBOX ERROR: FAILED IDS MAPPING TO EMAIL</h1>'; // echo '<pre>',var_dump($lstMsgIdToEmail),'</pre>'; /** * ---------------------------------- */ function writeData($data, $filename) { file_put_contents(__DIR__ . '/result_' . $filename . '_seri.log', serialize($data)); file_put_contents(__DIR__ . '/result_' . $filename . '_dump.log', var_export($data, true)); } function getFailureText($line)