date('d.m.Y', strtotime('+1 day', time()))
Также можно использовать '+6 days', '+1 week' и тд.
date('d.m.Y', strtotime('+1 day', time()))
; Вычисление модуля
(define (abs x)
(cond ((< x 0) (- x))
(else x)))
(define (abs x)
(if (< x 0) ; Предикат
(- x) ; Следствие
x)) ; Альтернатива
Код:
$newsXML = new SimpleXMLElement("<news></news>");
$newsXML->addAttribute('newsPagePrefix', 'value goes here');
$newsIntro = $newsXML->addChild('content');
$newsIntro->addAttribute('type', 'latest');
$newsXML->content = 'hello!';
Header('Content-type: text/xml');
echo $newsXML->asXML();
Результат:
<?xml version="1.0"?>
<news newsPagePrefix="value goes here"><content type="latest">hello!</content></news>
Объект вида можно хранить, допустим в реестре, а вообще как хотим.
$view = new Zend_View();
$view->setHelperPath('Custom/View/Helper/', 'Custom_View_Helper_');
Собственно и все, просто указали хелпер вида для отображения, в данном случае.
class Custom_Form_Element_Securimage extends Zend_Form_Element
{
public $helper = 'Securimage';
}
class Custom_View_Helper_Securimage extends Zend_View_Helper_FormElementОдноименный метод хелпера возвращает html-код нашего элемента.
{
public function securimage($name, $value = null, $attribs = null)
{
$html = "<img src='http://path/to/captcha' />";
$html .= "<input type='text' name='{$name}' />";
return $html;
}
}
?>
class Custom_Validate_Securimage extends Zend_Validate_AbstractОсталось совсем немного, создать форму и добавить туда наш элемент, примерно так ...
{
const INVALID = 'invalid';
protected $_messageTemplates = array(
self::INVALID => 'Неверный код'
);
public function isValid($val, $context = null)
{
$val = (string) $val;
$this->_setValue($val);
$si = new Securimage();
if(!$si->check($val)) {
$this->_error(self::INVALID);
return false;
}
return true;
}
}
class MyForm extends Zend_FormПути к файлам элемента и валидатора указывать не требуется, все включается автоматически.
{
pulic function init()
{
// ....
$si = new Custom_Form_Element_Securimage('cap');
$si->addValidator(new Custom_Validate_Securimage());
$si->setRequired();
$si->setLabel('Код');
$this->addElement($si);
// ....
}
}
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
class MyFilter implements Zend_Filter_Interface
{
public function filter($value)
{
return $valueFiltered;
}
}
// Использование
$filterChain = new Zend_Filter();
$filterChain->addFilter(new MyFilter());
eval { # try
... тут наш код ...
};
if( $@ ) { # catch
... тут обработка исключений $@ ...
}
$remote_img = 'http://www.somwhere.com/images/image.jpg';
$img = imagecreatefromjpeg($remote_img);
$path = 'images/';
imagejpeg($img, $path);
// CURL
function save_image($img,$fullpath)
{
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
my $dbh = DBI->connect("DBI:mysql:database=$db_name;mysql_socket=/opt/lampp/var/mysql/mysql.sock",
$db_user, $db_pwd);
#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
use threads::shared;
my $var: shared;
$var = 0;
my @threads;
for(1..10) {
new threads(\&myThread, $_);
}
$_->join for threads->list;
sub myThread
{
my $thrn = shift;
printf "thread %d started at %s\n", $thrn, scalar localtime time;
while($var < 100) {
#printf "thread #%d: var=%d\n", $thrn, $var;
$var++;
sleep 1;
}
printf "thread %d stopped at %s\n", $thrn, scalar localtime time;
}
leon@leon-desktop:/opt/lampp/htdocs/allmuz/application/scripts$ ./autocomments.pl
thread 1 started at Wed Aug 11 11:52:20 2010
thread 2 started at Wed Aug 11 11:52:20 2010
thread 3 started at Wed Aug 11 11:52:20 2010
thread 4 started at Wed Aug 11 11:52:20 2010
thread 5 started at Wed Aug 11 11:52:20 2010
thread 6 started at Wed Aug 11 11:52:20 2010
thread 7 started at Wed Aug 11 11:52:20 2010
thread 8 started at Wed Aug 11 11:52:20 2010
thread 9 started at Wed Aug 11 11:52:20 2010
thread 10 started at Wed Aug 11 11:52:20 2010
thread 1 stopped at Wed Aug 11 11:52:30 2010
thread 2 stopped at Wed Aug 11 11:52:30 2010
thread 3 stopped at Wed Aug 11 11:52:30 2010
thread 4 stopped at Wed Aug 11 11:52:30 2010
thread 5 stopped at Wed Aug 11 11:52:30 2010
thread 6 stopped at Wed Aug 11 11:52:30 2010
thread 7 stopped at Wed Aug 11 11:52:30 2010
thread 8 stopped at Wed Aug 11 11:52:30 2010
thread 9 stopped at Wed Aug 11 11:52:30 2010
thread 10 stopped at Wed Aug 11 11:52:30 2010
Что-то вроде array_rand для PHP:
use List::Util qw/shuffle/; my @pop = (1..100); my $samples = 30; my @sample = (shuffle(@pop))[0..$samples-1]; print "@sample";