Публикации с тегом "PHP"

????????? ???? ?? MySQL ? PHP

??? ????????, ? MySQL ???? ??? ???????? ???? ?????? ??? ???????? ???: date ? datetime. ?????? ???????, ?? ????, ???????? ??????????? ????????? ??????? ? ????????? ?????? ???? ??????? ? ?????. ??? ?????????? ?? MySQL ?????? ?????? ???? ?? ???????? ?????? ?????????????? ????????? ????????:

2012-03-03
2012-03-03 12:00:00

?????? ? PHP ? ??????????? ???????? ?????? ? ?????? ???????????? ??? ?????????? ?????? ???? Unix timestamp, ?????????????? ?? ???? ????? ?????????? ?????? ????? "?????? ?????" (???????? ??????? ?????? 1970 ????) ? ??????? ????????.

????? ??? ?????? ???????? ???????? ?? ?????????????? ????? ???????? ????, ?????? ? ?.?. ? ???????? ?? ? PHP-??????? mktime, ?? ? ????????? ??????? ?????. ?????????? MySQL-??????? Unix_timestamp, ??????? ????????? ????????????? ???? ?? ??????? MySQL ? ?????? Unix timestamp ?? ????? ???????. ???????????? ????????? ???????:

SELECT created                 AS created_mysql,
       Unix_timestamp(created) AS created_unix
FROM   articles;

????????? ?????????? HTML-????? ??? ?????? PHP

??????? ??? ???? ?????, ????? ????-?? ??????????. ???? ???????? ? ??????????? ???? ? ?????? ?? ???????:

function random_html_color()
{
    return sprintf( '#%02X%02X%02X', rand(0, 255), rand(0, 255), rand(0, 255) );
}

?????? RGB-???????????? ????? ???????????? ? ??????? rand(0, 255), ????? ??????? ??, ??????, rand(0, 120) ????? ???????????? ?????????, ?? ?????? ?????.

??????? ???? ?? PHP

???? ?????????? ????????, ??????? ????????? ???????????? ???? ? ??????????????? ???????? ? ????? ??????:

function rusdate($d, $format = 'j %MONTH% Y', $offset = 0)
{
    $montharr = array('??????', '???????', '?????', '??????', '???', '????', '????', '???????', '????????', '???????', '??????', '???????');
    $dayarr = array('???????????', '???????', '?????', '???????', '???????', '???????', '???????????');
 
    $d += 3600 * $offset;
 
    $sarr = array('/%MONTH%/i', '/%DAYWEEK%/i');
    $rarr = array( $montharr[date("m", $d) - 1], $dayarr[date("N", $d) - 1] );
 
    $format = preg_replace($sarr, $rarr, $format); 
    return date($format, $d);
}

?????? ???????? ?????-????, ?????? ?????? ????????? ????. ??? ????????? ????????? ?????????? PHP-??????? date(), ?????? ? ??????? ????? ???????? ??? ?????????????? ???????:



            

?????? ????? ?? PHP

???? (??????) ???? ?? ???????? ???????????????? ????????? ?????. ???-?????? ??? ?????????? ?????????? ?? ???? ??????????? ?? ????????? ????? ???????? ????, ??????? ????????? ?????? ?? ????????. ???????????? ?? ????? ???????? ????? ? ????? ????????? ?? ?????.

????????? ???? ??????????? ? ????????? ??????, ????? ???? ?????????? ???????????. ?? ???? ?????, ????????, ???? ?? ????????? ???? PHP ? HTML.

?????? ????? ??? ???? ? ???????????? ??????????? ????? ?????????? ????? ?????. ??? ???, ??? ?????????? ???, ??? ?????? ????????? ?? ???????? ? ??????.

???????? ????? ? ???? ??????

??? ?????? ???????????, ????? ??????? ????? ??????? ???? ??? ?????? ? ???? ??????. ?????? ??????? ???? ????? ??????? ? ????????? ???? ??? ?????? ?????? ?????? ???????, ??? ??? ?????????? ?????????? ?????? ? ?????? ?? ????? ????? ????? ??????? ? ?????????. ????? ??????????? ??????, ? ?????? ??? ????? "?????? ?? ??????" ????? ????????? ?????? ? ????? ??? ?????? ????????????? ???????.

???????? ????? (captcha) ?? PHP ????? 2

? ?????????? ?????? ??? ???????? ????? ?? PHP ? ?????? ???????? ?????? ????????????? ????????? ????? ?? ????????. ???, ???????, ???? ?????. ? ?????????????? ?????? ? ??? ?????????? ????????? ?????????? ?????:

<?php
 
  $letters = 'ABCDEFGKIJKLMNOPQRSTUVWXYZ';
 
  $caplen = 6;
  $width = 120; $height = 20;
  $font = 'comic.ttf';
  $fontsize = 14;
 
  header('Content-type: image/png');
 
  $im = imagecreatetruecolor($width, $height);
  imagesavealpha($im, true);
  $bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
  imagefill($im, 0, 0, $bg);
 
  putenv( 'GDFONTPATH=' . realpath('.') );
 
  $captcha = '';
  for ($i = 0; $i < $caplen; $i++)
  {
    $captcha .= $letters[ rand(0, strlen($letters)-1) ];
    $x = ($width - 20) / $caplen * $i + 10;
    $x = rand($x, $x+4);
    $y = $height - ( ($height - $fontsize) / 2 );
    $curcolor = imagecolorallocate( $im, rand(0, 100), rand(0, 100), rand(0, 100) );
    $angle = rand(-25, 25);
    imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]);
  }
 
  session_start();
  $_SESSION['captcha'] = $captcha;
 
  imagepng($im);
  imagedestroy($im);
 
?>