本文整理汇总了PHP中cleanup函数的典型用法代码示例。如果您正苦于以下问题:PHP cleanup函数的具体用法?PHP cleanup怎么用?PHP cleanup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanup
function cleanup($path, $max_age) {
$max_age_seconds = $max_age * 60 * 60 * 24;
$files_left = 0;
if ($dh = @opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$filepath = "$path/$file";
if (is_dir($filepath)) {
if (cleanup($filepath, $max_age) == 0) {
rmdir($filepath);
} else {
$files_left++;
}
} else {
if (file_older($filepath, $max_age_seconds)) {
unlink($filepath);
} else {
$files_left++;
}
}
}
}
closedir($dh);
}
return $files_left;
}
示例2: findconsolidatephase
function findconsolidatephase($game_id, $terr)
{
$result = mysql_query("SELECT throne1, throne2, throne3, throne4, throne5, throne6 FROM game where id={$game_id}");
$row = mysql_fetch_assoc($result);
$orders = array('G' => 0, 'B' => 0, 'L' => 0, 'S' => 0, 'T' => 0, 'M' => 0);
$result2 = mysql_query("SELECT name, control, prikaz FROM {$terr}");
$i = 0;
while ($array2 = mysql_fetch_assoc($result2)) {
if ($array2['prikaz'] == 6 || $array2['prikaz'] == 11) {
$orders[$array2['control']]++;
}
$i++;
}
$orders2 = array('Greyjoy' => $orders['G'], 'Baratheon' => $orders['B'], 'Lannister' => $orders['L'], 'Stark' => $orders['S'], 'Tyrell' => $orders['T'], 'Martell' => $orders['M']);
if ($orders2[$row['throne1']] == 0) {
mysql_query("UPDATE `game` SET currentplayer = currentplayer+1 WHERE `id` = {$game_id}");
if ($orders2[$row['throne2']] == 0) {
mysql_query("UPDATE `game` SET currentplayer = currentplayer+1 WHERE `id` = {$game_id}");
if ($orders2[$row['throne3']] == 0) {
mysql_query("UPDATE `game` SET currentplayer = currentplayer+1 WHERE `id` = {$game_id}");
if ($orders2[$row['throne4']] == 0) {
mysql_query("UPDATE `game` SET currentplayer = currentplayer+1 WHERE `id` = {$game_id}");
if ($orders2[$row['throne5']] == 0) {
mysql_query("UPDATE `game` SET currentplayer = currentplayer+1 WHERE `id` = {$game_id}");
if ($orders2[$row['throne6']] == 0) {
/*mysql_query("UPDATE `game` SET turn = turn+1, faza = 0, currentplayer = 0 WHERE `id` = $game_id");*/
cleanup($game_id, $terr);
}
}
}
}
}
}
}
示例3: removal
function removal()
{
global $link;
$sql = "DROP DATABASE " . $_SESSION["modCode"];
if (mysql_query($sql, $link)) {
$db = mysql_select_db('nell', $link) or die("Couldn't select database");
if (mysql_query("DELETE FROM modules WHERE mod_code = '" . $_SESSION["modCode"] . "'")) {
echo '
<div class = "form-group">
<h1>
' . $_SESSION["modCode"] . ' has been deleted
</h1>
</div>
<div class = "form-group">
<a href = "adminPage.php">
Click here to return to the Administrative Homepage
</a>
</div>';
} else {
$code = 2.1;
failureMessage($code);
}
} else {
$code = 2.2;
failureMessage($code);
}
cleanup();
}
示例4: removal
function removal()
{
if ($query = mysql_query("UPDATE modules SET lecturer_id = NULL WHERE lecturer_id = " . $_SESSION["lecCode"] . " AND mod_code = '" . $_SESSION["modCode"] . "'")) {
echo '
<div class = "form-group">
<h1>
' . $_SESSION["l_name"] . ', ' . $_SESSION["f_name"] . ' has been removed from ' . $_SESSION["modCode"] . '
</h1>
</div>
<div class = "form-group">
<a href = "adminPage.php">
Click here to return to the Administrative Homepage
</a>
</div>';
cleanup();
} else {
echo '
<div class = "form-group">
<h1>
Error 6
</h1>
<br/>
<h3>
' . $_SESSION["l_name"] . ', ' . $_SESSION["f_name"] . ' could not be removed from ' . $_SESSION["modCode"] . '
</h3>
</div>
<div class = "form-group">
<a href = "adminPage.php">
Click here to return to the Administrative Homepage
</a>
</div>';
cleanup();
}
}
示例5: getPageTree
function getPageTree($parent)
{
global $admin, $database, $InternPagesSelectBox, $PagesTitleSelectBox;
$sql = 'SELECT * FROM `' . TABLE_PREFIX . 'pages` ';
$sql .= 'WHERE `parent`= ' . (int) $parent . ' ';
$sql .= PAGE_TRASH != 'inline' ? 'AND `visibility` != \'deleted\' ' : ' ';
$sql .= 'ORDER BY `position` ASC';
if ($resPage = $database->query($sql)) {
while (!false == ($page = $resPage->fetchRow())) {
if (!$admin->page_is_visible($page)) {
continue;
}
$menu_title = cleanup($page['menu_title']);
$page_title = cleanup($page['page_title']);
// Stop users from adding pages with a level of more than the set page level limit
if ($page['level'] + 1 <= PAGE_LEVEL_LIMIT) {
$title_prefix = '';
for ($i = 1; $i <= $page['level']; $i++) {
$title_prefix .= ' - ';
}
$InternPagesSelectBox .= "new Array( '" . $title_prefix . $menu_title . "', '[wblink" . $page['page_id'] . "]'), ";
$PagesTitleSelectBox .= "new Array( '" . $page_title . "', '[wblink" . $page['page_id'] . "]'), ";
}
getPageTree($page['page_id']);
}
}
}
示例6: test_function
function test_function($step)
{
$html = <<<EOF
<div>lorem ipsum doLor sit amet, ludus munere at Quo, <a href=“#”>mel hinc pAulo concludaturque te</a>. illum populo
iracundia Id nam, his ne elitr impedit, Nominavi adipiscinG ex his.</div>
EOF;
$string = $html;
$arr = array();
if ($step >= 1) {
$string = strip_tags($html);
}
if ($step >= 2) {
$string = preg_replace('#\\s+#', ' ', $string);
}
if ($step >= 3) {
$string = strtolower($string);
}
if ($step >= 4) {
$arr = explode(" ", $string);
}
if ($step >= 5) {
$arr[0] = ucfirst($arr[0]);
for ($i = 1; $i < count($arr); $i++) {
if (substr($arr[$i - 1], -1) == ".") {
$arr[$i] = ucfirst($arr[$i]);
}
}
$string = implode(" ", $arr);
}
$pass = true;
$message = "There's a problem with your code, try again!";
switch ($step) {
case 1:
$pass = assert(cleanup($html) == $string);
$message = "Your code hasn't removed all tags, try again!";
break;
case 2:
$pass = assert(cleanup($html) == $string);
$message = "Your code hasn't removed the extraneous white space, try again!";
break;
case 3:
$pass = assert(cleanup($html) == $string);
$message = "Your code hasn't made mid-word letters lowercase, try again!";
break;
case 4:
$pass = assert(cleanup($html) == $arr);
$message = "Something's not right, try again!";
break;
case 5:
$pass = assert(cleanup($html) == $string);
$message = "Your code hasn't correctly cased the string, try again!";
break;
}
if ($pass) {
echo json_encode(array('pass' => true));
} else {
echo json_encode(array('pass' => false, 'message' => $message));
}
}
示例7: sc_slideshow
/**
* Create a javascript slideshow of each top level element in the
* shortcode. All attributes are optional, but may default to less than ideal
* values. Available attributes:
*
* height => css height of the outputted slideshow, ex. height="100px"
* width => css width of the outputted slideshow, ex. width="100%"
* transition => length of transition in milliseconds, ex. transition="1000"
* cycle => length of each cycle in milliseconds, ex cycle="5000"
* animation => The animation type, one of: 'slide' or 'fade'
*
* Example:
* [slideshow height="500px" transition="500" cycle="2000"]
* <img src="http://some.image.com" .../>
* <div class="robots">Robots are coming!</div>
* <p>I'm a slide!</p>
* [/slideshow]
**/
function sc_slideshow($attr, $content = null)
{
$content = cleanup(str_replace('<br>', '', $content));
$content = DOMDocument::loadHTML($content);
$html = $content->childNodes->item(1);
$body = $html->childNodes->item(0);
$content = $body->childNodes;
# Find top level elements and add appropriate class
$items = array();
foreach ($content as $item) {
if ($item->nodeName != '#text') {
$classes = explode(' ', $item->getAttribute('class'));
$classes[] = 'slide';
$item->setAttribute('class', implode(' ', $classes));
$items[] = $item->ownerDocument->saveXML($item);
}
}
$animation = $attr['animation'] ? $attr['animation'] : 'slide';
$height = $attr['height'] ? $attr['height'] : '100px';
$width = $attr['width'] ? $attr['width'] : '100%';
$tran_len = $attr['transition'] ? $attr['transition'] : 1000;
$cycle_len = $attr['cycle'] ? $attr['cycle'] : 5000;
ob_start();
?>
<div
class="slideshow <?php
echo $animation;
?>
"
data-tranlen="<?php
echo $tran_len;
?>
"
data-cyclelen="<?php
echo $cycle_len;
?>
"
style="height: <?php
echo $height;
?>
; width: <?php
echo $width;
?>
;"
>
<?php
foreach ($items as $item) {
?>
<?php
echo $item;
?>
<?php
}
?>
</div>
<?php
$html = ob_get_clean();
return $html;
}
示例8: findresults
function findresults($term)
{
global $terms, $search_results, $base_terms, $base_url;
$url = $base_url . urlencode("how to " . $term);
$url = $base_url . urlencode($term);
$results = file_get_contents($url);
if ($results == "") {
error_log("error getting results, throttling\n");
array_push($terms, $term);
throttle();
return;
}
$x = strpos($results, "new Array");
if ($x === false) {
error_log("got {$results} for {$url}");
return;
}
$x += strlen("new Array");
$y = strpos($results, "new Array", $x + 1);
$urls = substr($results, $x, $y - $x - 2);
$urls = cleanup($urls);
if ($urls == "") {
return;
}
// trim the results
$url_array = explode(",", $urls);
$x = $y + strlen("new Array");
$y = strpos($results, "new Array", $x + 1);
$results = substr($results, $x, $y - $x - 2);
$results = cleanup($results);
$results = preg_replace('/([0-9]),([0-9])/', '$1$2', $results);
$results = str_replace(" results", "", $results);
$count_array = explode(",", $results);
if (sizeof($url_array) == 10) {
//print("Adding terms for $term\n");
foreach ($base_terms as $b) {
if (strlen($term . $b) < 6) {
array_push($terms, $term . $b);
}
}
// add a space only if it isn't already there
if (substr($term, strlen($term) - 1, 1) != ' ') {
array_push($terms, $term . " ");
//printf("Adding space to +$term+ -" . substr($term, strlen($term)-1, 1) . "-\n");
}
//print("Terms are now " . sizeof($terms) . " long\n");
}
// print_r($array);
for ($i = 0; $i < sizeof($url_array); $i++) {
$a = $url_array[$i];
$x = array();
$x[0] = $term;
$x[1] = $a;
$x[2] = $count_array[$i];
$search_results[] = $x;
}
throttle();
}
示例9: runcmd
function runcmd($desc, $cmd)
{
echoln($desc);
$ret = 0;
system($cmd, $ret);
if ($ret) {
cleanup();
exit;
}
}
示例10: halt
/**
* Outputs error messages, cleans up temporaray tables, then dies
* NOTE: Halts execution via die();
* @param $messages mixed Array of messages to output
*/
function halt($messages)
{
// Iterate over the messages, cleanup and die
if (is_array($messages)) {
foreach ($messages as $message) {
echo "*** {$message}\n";
}
} else {
echo "*** {$messages}\n";
}
cleanup();
die;
}
示例11: main
function main()
{
function cleanup()
{
global $wpdb;
// we need to ensure that we switch off this database
$wpdb->select(null);
// drop our test database
// XXX: why cant we use $wpdb->query ?
mysql_query(sprintf('DROP DATABASE `%s`', DISQUS_TEST_DATABASE)) or die(mysql_error());
}
global $wpdb;
// $this->query(sprintf('DROP DATABASE IF EXISTS `%s`', DISQUS_TEST_DATABASE));
// check existance of test db
$exists = $wpdb->get_var($wpdb->prepare('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \'%s\'', DISQUS_TEST_DATABASE));
if (!empty($exists)) {
printf("Test database '%s' already exists. Continuing will drop this database and all data!\nContinue? [y/n]\n", $exists);
$handle = fopen("php://stdin", "r");
$line = strtolower(trim(fgets($handle)));
if ($line != 'yes' && $line != 'y') {
echo "ABORTING!\n";
exit;
}
}
// setup database
$wpdb->query(sprintf('CREATE DATABASE `%s`', DISQUS_TEST_DATABASE));
$wpdb->select(DISQUS_TEST_DATABASE);
// $fp = fopen('initial.sql', 'r');
// $buffer = '';
// while (($line = fgets($fp)) !== false) {
// $buffer .= trim($line);
// if (strpos($line, ';')) {
// if (!empty($buffer)) {
// $this->query($buffer);
// }
// $buffer = '';
// }
// }
//
try {
$suite = new PHPUnit_Framework_TestSuite('DisqusPluginTest');
$result = $suite->run();
require_once 'PHPUnit/TextUI/ResultPrinter.php';
$printer = new PHPUnit_TextUI_ResultPrinter();
$printer->printResult($result);
cleanup();
} catch (Exception $ex) {
cleanup();
throw $ex;
}
}
示例12: init
function init()
{
global $fail, $pass, $error;
$fail = 0;
$pass = 0;
$error = 0;
rename("modules", "modules.tmp") or error("Couldn't move 'modules' directory\n");
mkdir("modules") or error("Couldn't create 'modules' directory\n");
rename("admin.sqlite", "admin.sqlite.tmp") or error("Couldn't move 'admin.sqlite'\n");
# if something went wrong already, bail
if ($error) {
cleanup();
}
}
示例13: transform
/**
* Find TeX code in text, transform it to images and put images to text.
* @param string $text Text.
* @return string Transformed text.
*/
function transform($text)
{
preg_match_all("/\\[tex\\](.*?)\\[\\/tex\\]/si", $text, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$position = strpos($text, $matches[0][$i]);
$code = $matches[1][$i];
$hash = md5(preg_replace('/\\s/', '', $code));
$full_name = Config::ABS_PATH . "/latexcache/{$hash}.png";
$url = Config::DIR_PATH . "/latexcache/{$hash}.png";
if (!is_file($full_name)) {
render_latex($code, $hash);
cleanup($hash);
}
$text = substr_replace($text, "<img src=\"{$url}\" alt=\"Formula: {$i}\" />", $position, strlen($matches[0][$i]));
}
return $text;
}
示例14: get_info
function get_info() {
reset_product_array();
get_fields();
cleanup();
set_skus();
set_vendor_code();
set_sku_str();
set_brand();
set_name();
set_type();
set_price();
set_features();
set_description();
set_keywords();
set_main_image();
output_product_str();
}
示例15: getPageTree
function getPageTree($parent)
{
global $admin, $database, $InternPagesSelectBox, $PagesTitleSelectBox;
$sql = 'SELECT * FROM `' . TABLE_PREFIX . 'pages` ' . 'WHERE `parent`= ' . (int) $parent . ' AND ' . '`level`<=' . PAGE_LEVEL_LIMIT . ' ' . (PAGE_TRASH != 'inline' ? 'AND `visibility` != \'deleted\' ' : ' ') . 'ORDER BY `position` ASC';
if ($resPage = $database->query($sql)) {
while (!(false == ($page = $resPage->fetchRow(MYSQLI_ASSOC)))) {
if (!$admin->page_is_visible($page)) {
continue;
}
$menu_title = cleanup($page['menu_title']);
$page_title = cleanup($page['page_title']);
$title_prefix = str_repeat(' - ', $page['level']);
$InternPagesSelectBox .= "new Array( '" . $title_prefix . $menu_title . "', '[wblink" . $page['page_id'] . "]'), ";
$PagesTitleSelectBox .= "new Array( '" . $page_title . "', '[wblink" . $page['page_id'] . "]'), ";
if ($page['level'] < PAGE_LEVEL_LIMIT) {
getPageTree($page['page_id']);
}
}
}
}