PHP Basics Introduction to PHP • a PHP file, PHP workings, running PHP. • Basic PHP syntax • variables, operators, if...else...and switch, while, do while, and for. Some useful PHP functions How to work with • HTML forms, cookies, files, time and date. How to create a basic checker for user-entered data
25
Embed
PHP Basics Introduction to PHP a PHP file, PHP workings, running PHP. Basic PHP syntax variables, operators, if...else...and switch, while, do while, and.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
PHP Basics
Introduction to PHP• a PHP file, PHP workings, running PHP.• Basic PHP syntax• variables, operators, if...else...and switch, while, do while, and for.
Some useful PHP functions
How to work with • HTML forms, cookies, files, time and date.
How to create a basic checker for user-entered data
PHP
توسط راسموس ِل�ردورت ابداع شد.1995در سال .در اصل برای ردیابی مشاهده کنندگان وب سایت ِل�ردورت درست شد بعد از دو سال به همراه آپاچی یکی از بهترین ابزارهای توِلید صفحات
دینامیک شد..یک زبان اسکریپتی رایگان و با کد باز است کامال باmySQL.سازگار است
PHP مثل جاوا اسکریپت است منتهی در سمت سرور کار می کند.
یعنی با برچسپهای مخصوص و داخل کدHTML .جاسازی می شود ( از روی نوع فایل.php یا .phtml سرور متوجه می شود با متن )PHP
سروکار دارد. سرور کدPHP را اجرا و نتیجه را داخل صفحه HTML.قرار می دهد ِلذا کاربر هیچوقت کدPHP .را نمی بیند و فقط نتیجه اجرا را می بیند
What do You Need?
شما به نرم افزارهای زیر برای اجرای وب سایتهایی که با PHP:می نویسید دارید
PHP- زبان اسکریپت نویسی 1MySQL –پایگاه داده 2iis- وب سرور آپاچی یا 3
Download PHP for free here: http://www.php.net/downloads.php
Download MySQL for free here: http://www.mysql.com/downloads/index.html
Download Apache for free here: http://httpd.apache.org/download.cgi
Basic PHP syntax
PHPهر قطعه کد بین برچسپهای
?<php قرار ?< ومی گیرد .
دستوراتprint و echo برای نمایش
خروجی هر دستور باید با;
خاتمه یابد غیر از آخرین •
دستور که اختیاری ;وجود است.
برای توضیحات //تک خطی
*/ برای */ و توضیحات چند خطی
<html><!-- hello.php COMP519 --><head><title>Hello World</title></head><body> <p>This is going to be ignored by the PHP interpreter.</p>
<?php echo ‘<p>While this is going to be parsed.</p>‘; ?>
<p>This will also be ignored by PHP.</p>
<?php print(‘<p>Hello and welcome to <i>my</i> page!</p>'); ?>
<html><head></head><body><!–- switch-cond.php COMP519 --><?php$x = rand(1,5); // random integerecho “x = $x <br/><br/>”;switch ($x){case 1: echo "Number 1"; break;case 2: echo "Number 2"; break;case 3: echo "Number 3"; break;default: echo "No number between 1 and 3";}?>
</body></html>
switch (expression){case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break;default: code to be executed if expression is different from both label1 and label2;}
PHP Information نصب شده استفاده می گردد.PHPبرای نمایش اطالعات کلی نسخه )(phpinfo تابع
<html><head></head><!– info.php COMP519<body><?php// Show all PHP informationphpinfo();?><?php// Show only the general informationphpinfo(INFO_GENERAL);?></body></html>
INFO_GENERAL The configuration line, php.ini location, build date, Web Server, System and more
INFO_CREDITS PHP 4 creditsINFO_CONFIGURATION Local and master values
for php directives
INFO_MODULES Loaded modules
INFO_ENVIRONMENT Environment variable information
INFO_VARIABLES All predefined variables from EGPCS
INFO_LICENSE PHP license information
INFO_ALL Shows all of the above (default)
view the output page
Server Variables
_$SERVER.یک متغییر رزرو شده است که تمام اطالعات سرور از طریق آن قابل دسترسی است این متغییر یک متغییر عمومی است.
<?php$myFile = "testFile.txt";$fh = fopen($myFile, 'a') or die("can't open file");$stringData = "New Stuff 1\n";fwrite($fh, $stringData);$stringData = "New Stuff 2\n";fwrite($fh, $stringData);fclose($fh);?>