Примеры php страниц
Чтобы использовать примеры, скачайте и используйте один из редакторов.
$text=’Этот чёртов мир!!!’;
echo ($text);
? >
$str = ’10’;
$index = 2 * $str;
echo $index, “< br >”;
? >
define(“MY_CONST”,”Привет, страна!”);
echo MY_CONST; # выведет на экран текст
? >
/*
А это комментарий
из множества строк
*/
echo “Привет!
“;
echo “Меня зовут Коля!”;
? >
#Задание функции
function HW()
{
echo “Hello world!”;
}
# Вызов функции
HW();
? >
phpinfo();
? >
$parts = array(“Это ячейка 0”, “Это ячейка 1”, “Это ячейка 2”);
echo $parts[0];
? >
// Получение первого символа строки
$str = ‘Это простой текст’;
$first = $str{0};
// Получение третьего символа строки
$third = $str{2};
// Получение последнего символа строки
$str = ‘Это продолжение текста’;
$last = $str{strlen($str)-1};
// Изменение последнего символа строки
$str = ‘Посмотри на море’;
$str{strlen($str)-1} = ‘я’;
? >
echo getenv(‘REMOTE_ADDR’);
?>
define(‘ST_T’, microtime());//Старт загрузки
echo ‘<p>Тут текст страницы</p>’;
printf(‘Страница создана за %.5f сек.’, microtime()-ST_T);//вывод результата
?>
echo highlight_string(“#Здесь пишем код#”);
?>
echo rand(1,100); //Генерируются от 1 до 100
?>
echo filesize(‘image.jpg’).’ байт’;//Укажите свою ссылку на файл
?>
function transliterate_text($tt)
{
$tt = strtr($tt, array(‘а’=>’a’,’А’=>’A’,’б’=>’b’,’Б’=>’B’,
‘в’=>’v’,’В’=>’V’,’г’=>’g’,’Г’=>’G’,’д’=>’d’,’Д’=>’D’,
‘е’=>’e’,’Е’=>’E’,’ё’=>’e’,’Ё’=>’E’,’ж’=>’zh’,’Ж’=>’ZH’,
‘з’=>’z’,’З’=>’Z’,’и’=>’i’,’И’=>’I’,’й’=>’y’,’Й’=>’Y’,
‘к’=>’k’,’К’=>’K’,’л’=>’l’,’Л’=>’L’,’м’=>’m’,’М’=>’M’,
‘н’=>’n’,’Н’=>’N’,’о’=>’o’,’О’=>’O’,’п’=>’p’,’П’=>’P’,
‘р’=>’r’,’Р’=>’R’,’с’=>’s’,’С’=>’S’,’т’=>’t’,’Т’=>’T’,
‘у’=>’u’,’У’=>’U’,’ф’=>’f’,’Ф’=>’F’,’х’=>’h’,’Х’=>’H’,
‘ц’=>’ts’,’Ц’=>’TS’,’ч’=>’ch’,’Ч’=>’CH’,’ш’=>’sh’,
‘Ш’=>’SH’,’щ’=>’shch’,’Щ’=>’SHCH’,’ъ’=>”,’Ъ’=>”,’ы’=>’i’,
‘Ы’=>’I’,’ь’=>”’,’Ь’=>”’,’э’=>’e’,’Э’=>’E’,’ю’=>’yu’,
‘Ю’=>’YU’,’я’=>’ya’,’Я’=>’YA’));
return $tt;
}
$line = ‘Всем привет’;
echo transliterate_text($line);
?>
echo ‘Вы находитесь на сайте ‘.$_SERVER[‘HTTP_HOST’];
?>
header(‘Location: http://uchitel-program.ru/’);
exit;
?>
header(‘Refresh: 3; URL=http://uchitel-program.ru/’);
echo ‘Через 3 сек. вы будете перенаправлены на другую страницу’;
exit;
?>
<url domain=”http://uchitel-program.ru/”>/</url>
<tcy rang=”4″ value=”250″/>
<topics> </topics>
<textinfo> </textinfo>
</urlinfo>
echo rand(0,576);
?>
$my_int = round(4.7);
echo($my_int);
$my_int = round(-4.7);
echo($my_int);
$my_int = round(-4.5);
echo($my_int);
?>
$start = array(0, 0);
$end = array(100, 0);
$length = sqrt(pow($end[0] – $start[0], 2) + pow($end[1] – $start[1], 2));
$angle = 35;
$r = deg2rad($angle);
$new_start = array(20, 20);
$new_end = array($new_start[0] + cos($r) * $length, $new_start[1] + sin($r) * $length);
var_dump($new_end);
?>
$cos1 = cos(10);
$cos2 = cos(deg2rad(80));
?>
$sin1 = sin(10);
$sin2 = sin(deg2rad(80));
?>
$tan1 = tan(10);
$tan2 = tan(deg2rad(80));
?>
$clothes = array( ‘hats’ => 75, ‘coats’ => 32, ‘shoes’ => 102,);
uasort($clothes, ‘evenfirst’);
var_export($clothes);
printf(“<p>Most items: %d; least items: %d.</p>\n”,
max($clothes), min($clothes));
?>
$somevar = 5 + 5; // 10
$somevar = 5 – 5; // 0
$somevar = 5 + 5 – (5 + 5); // 0
$somevar = 5 * 5; // 25
$somevar = 10 * 5 – 5; // 45
$somevar = $somevar . “appended to end”;
$somevar = false;
$somevar = !$somevar; // $somevar is now set to true
$somevar = 5;
$somevar++; // $somevar is now 6
$somevar–; // $somevar is now 5 again
++$somevar; // $somevar is 6
?>
print 2 + 2;
print 17 – 3.5;
print 10 / 3;
print 6 * 9;
?>
сп () Гиперболический косинус ( ехр ( аг ) + ехр ( -аг )) / 2
зп () Гиперболический синус ( ехр ( аг ) – ехр ( -аг )) / 2
Тань () Гиперболический тангенс зп ( аргумент ) / сп ( аргумент )
ACOSH () Гиперболический косинус
ASINH () Гиперболический синус
ATANH () Гиперболический арктангенс
<?php
$start = array(0, 0);
$end = array(100, 0);
$length = sqrt(pow($end[0] – $start[0], 2) + pow($end[1] – $start[1], 2));
$angle = 35;
$r = deg2rad($angle);
$new_start = array(20, 20);
$new_end = array( $new_start[0] + cos($r) * $length, $new_start[1] + sin($r) * $length
);
var_dump($new_end);
?>
$string_to_search = “showsuponceshowsuptwice”;
$string_to_find = “up”;
print(“Result of looking for $string_to_find” . strstr($string_to_search, $string_to_find));
$string_to_find = “down”;
print(“Result of looking for $string_to_find” . strstr($string_to_search, $string_to_find));
?>
$mixed_case_word = “Lower Case and Upper Case”;
$lowercase = strtolower($mixed_case_word);
print($lowercase);
?>
print(str_repeat(“cheers “, 3));
?>
$regex = “/^[\w\d!#$%&’*+-\/=?^'{|}~]+(\.[\w\d!#$%&’*+-\/=?^'{|}~]+)*@([a-z\d][-a-z\d]*[a-z\d]\.)+[a-z][-a-z\d]*[a-z]$/”;
$values = array(
“[email protected]”,
“[email protected]”
);
foreach ($values as $value) {
if (preg_match($regex, $value)) {
printf(“Found valid address: %s\n”, $value);
} else {
printf(“INVALID address: %s\n”, $value);
}
}
?>
$name = “john”;
print “hello, $name”;
?>
напечатать “Я пошел в магазин.” ;
печати “Стоимость соус \ $ 10.25.” ;
$ Стоимость = ‘$ 1 0.25 ‘;
печати “Стоимость соус $ Стоимость”. ;
печати “Стоимость соус \ $ \ 061 \ 060 \ x32 \ x35 “.. ;
?>
$ новая строка = “Новая строка \ п” ;
$ возвращение = “возврат каретки \ R” ;
Вкладка $ = “закладка \ т” ;
$ доллар = “Знак доллара является \ $” ;
$ двойных кавычек = “двойные кавычки является \” ” ;
?>
$header = “<html>\n”
. “<head>\n”
. “<title>String Operators</title>\n”
. “</head>\n”
. “<body>\n”;
$body_content = “body<br />\n”;
$footer = “</body>\n”
. “</html>\n”;
$page_content .= $header . $body_content . $footer;
print($page_content);
?>
$ рецепт = “3 столовые ложки дижонской горчицы
1/3 стакана Салат Цезарь туалетный
8 унций на гриле куриной грудки
3 чашки салата ромэн ” ;
/ / Преобразовать символы новой строки в <br />-х гг.
эхо nl2br ( $ рецепт ) ;
?>
$membership = “asdfadsf”;
if ( strlen( $membership ) == 4 )
print “Thank you!”;
else
print “Your membership number must have 4 digits<P>”;
?>
$myImage = ImageCreate(300,300);
$white = ImageColorAllocate ($myImage, 255, 255, 255);
$red = ImageColorAllocate ($myImage, 255, 0, 0);
$green = ImageColorAllocate ($myImage, 0, 255, 0);
$blue = ImageColorAllocate ($myImage, 0, 0, 255);
ImageFilledArc($myImage, 100, 100, 200, 150, 0, 90, $red, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 90, 180 , $green, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 180, 360 , $blue, IMG_ARC_PIE);
header (“Content-type: image/png”);
ImagePNG($myImage);
ImageDestroy($myImage);
?>
header(“Content-type: image/gif”);
$image = imagecreate( 200, 200 );
imagegif($image);
?>
$myImage = imagecreatefromgif(‘largeJava2sLogo.GIF’);
$myCopyright = imagecreatefrompng(‘logo.png’);
$destWidth = imagesx($myImage);
$destHeight = imagesy($myImage);
$srcWidth = imagesx($myCopyright);
$srcHeight = imagesy($myCopyright);
$destX = ($destWidth – $srcWidth) / 2;
$destY = ($destHeight – $srcHeight) / 2;
$white = imagecolorexact($myCopyright, 255, 255, 255);
imagecolortransparent($myCopyright, $white);
imagecopymerge($myImage, $myCopyright, $destX, $destY, 0, 0, $srcWidth, $srcHeight, 50);
header(“Content-type: image/jpeg”);
imagejpeg($myImage);
imagedestroy($myImage);
imagedestroy($myCopyright);
?>
<body>
<?php
$pic=ImageCreate(600,600);
$col1=ImageColorAllocate($pic,200,200,200);
$col2=ImageColorAllocate($pic,0,0,255);
ImageFilledRectangle($pic,1,1,100,100,$col2);
ImagePNG($pic,”pic.png”);
ImageDestroy($pic);
?>
<img src=”pic.png” border=0>
</body>
</html>
$myImage = ImageCreateFromPNG (“logo.png”);
$c = ImageColorAllocate ($myImage, 2, 255, 255);
ImageFilledEllipse($myImage, 10, 7, 20, 20, $c);
ImageFilledEllipse($myImage, 15, 7, 20, 20, $c);
ImageFilledEllipse($myImage, 20, 7, 20, 20, $c);
header (“Content-type: image/png”);
ImagePNG($myImage);
ImageDestroy($myImage);
?>
header(“Content-type: image/png”);
$image = imagecreate( 200, 200 );
$red = imagecolorallocate($image, 255,0,0);
$blue = imagecolorallocate($image, 0,0,255 );
imagearc( $image, 99, 99, 180, 180, 0, 360, $blue );
imagefill( $image, 99, 99, $blue );
imagepng($image);
?>
header (“Content-type: image/png”);
$im = ImageCreate (150, 150);
$grey = ImageColorAllocate ($im, 230, 230, 230);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageLine($im, 0, 30, 150, 150, $black);
ImageLine($im, 0, 150, 150, 30, $black);
ImageLine($im, 0, 30, 150, 30, $black);
ImageString($im, 3, 5, 5, “Figure 18.6: Lines”, $black);
ImagePng ($im);
ImageDestroy ($im);
?>
header(“Content-type: image/gif”);
$image = imagecreate( 200, 200 );
$red = imagecolorallocate($image, 255,0,0);
$blue = imagecolorallocate($image, 0,0,255 );
imageline( $image, 0, 0, 199, 199, $blue );
imagefill( $image, 0, 199, $blue );
imagegif($image);
?>
$baseimage = ImageCreateFromPNG(“logo.png”);
$myImage = ImageCreateFromPNG(“logo.png”);
$gray = ImageColorAllocate($myImage, 18, 18, 18);
ImageColorTransparent($myImage, $gray);
ImageCopyMerge($baseimage,$myImage,0,0,0,0,15,15,10);
header (“Content-type: image/png”);
ImagePNG($baseimage);
ImageDestroy($baseimage);
?>