بدايه بى اتش بى(الدرس الاول)
السلام عليكم ورحمه الله وبركاته النهارده ان شاء الله هتعرف ازاى نبدأ فى البى اتش بى
من المعروف طبعا ان عشان اكتب كود بى اتش بى لازم ليا سيرف اللى مهمته هفسر ليا الاوامر وكده راجع الدرس السابق
الاشهر طبعا هو سيرفر الاباتشى
وطبعا محتاج حاجه اكتب فيها اى محرر نصوص ممكن النودباد بتاع الويندوز بس ده مكروه جدا جدا يفتقد التنظيم ومش مترقم
طب وايه يعنى؟؟
احيانا او معظم الوقت تلاقى المتصفح بيقولك رساله خطا وجنبها رقم السطر اللى حصل عنده الخطا
تخيل لو انتا كاتب 1000 سطر وقالك الخطا فى السطر 5 هتقول هعد واشوفه طيب لو فى السطر 500؟؟؟؟
هتتمنى ان كودك مترقم دى نقطه ميزه تانيه برده لو انتا كاتب كلاسات ودوال هتلاقى الكلام داخل فى بعضه كله مش عارف تفرق لو احتجت ترجع للكود مره اخره طيب لو كل حاجه مميزهبلون معين اكيدهتبقى اسهل ليك ومريحه من هنا وجب الاشاره الى اهميه النود باد بلاس بلاس لانها تتوافر فيها هذه الشروط
وتقدر تحملها من هنا
- Notepad++ v5.9.3 Installer(to install it through setup file)
- Notepad++ v5.9.3 zip package(contain direct exe file deosn’t require setup)
- Notepad++ v5.9.3 7z package(same as the zip but different comprission type)
- Notepad++ v5.9.3 minimalist package
- SHA-1 digests for binary packages(for linux)
وطبعا اللى بيميز الصفحات الديناميكيه طبعا قواعد اليبانات ولذا يجب ان يتوفر لدينا محرك لقواعد اليبانات
وعشان محتاجين سيرفر ومحرك قواعد بيانات يبقى محتاجين برنامج
xamp( X = Linux or Windows or Mac OS X or Solaris/ A = Apache /M = MySQL. P = PHP P = Perl. )
وتقدر تحمله من هنا
XAMPP for Windows exists in three different flavors:
- Installer
- Probably the most comfortable way to install XAMPP.
- ZIP:
- For purists: XAMPP as ordinary ZIP archive.
- 7zip:
- For purists with low bandwidth: XAMPP as 7zip archive.
- ملاحظه هامه جدا لا تقوم بتسطيبه او وضعه على البارتشن الخاص بنسخه الويندوز اذا كانت فيستا اوسيفن
- لان الويندوز كده هيعطى له صلاحيات محدده لانه هيعامله كا يوزر وده هيوقف بعض الخدمات
- للناس الخبيره اعطى للبرنامج صلاحيات الادمنسترتور
- right click on setup file ____________>run as adminstrator
- or change partion
- كده اصبح لدينا كل ما يلزم لتشغيل ملفات البى اتش بى بقى لدينا معرفه كيفيه تشغيلها
- after install xamp
- then open it next press explore
- the opened window show xamp folders& files
- then open htdocs
- delete all files & foldrs but keep xamp folder
- save php file in that place
- then open the xamp click first admin button
- the browser will be opend showing u your files
- click on any file it show you your code excuted
- that’s all
- thanks
- اول كود لك بلغه بى اتش بى
- يوجد اكثر من صيغه لكتابه البى اتش بى
-
<?php print("hellow world"); - echo(“hellow world”);
-
?> - ___________________
<script language="php">
- print(“hellow world”);
- echo(“hellow world”);
</script>
- ________________________
<?
- print(“hellow world”);
- echo(“hellow world”);
?> ___________________________ <%
- print(“hellow world”);
- echo(“hellow world”);
%>
بعد الانتهاء من كتابه الكود قم بحفظه فى المكان الذى اشرت اليه سابقا
- _______________________________
- ملاحظات مهمه جدا
اى سطر اوامر فى البى اتش بى لابد ان ينتهى بفاصله منقوطه
;
كى نخبر المفس ان هذه هى نهايه الكود
__________________________________________________________
Comments
// This is a single-line comment /* This is a multi-line comment. */
______________________________________________
PHP Functions
لغه بى اتش بى يعتبر أهم مايميزها احتوائها على دوال عديده جدا ممايسهل عليك فعل ما تريد وبأبسط الطرق فالقاعده العامه لكتابه اى داله كالاتى
function_name(arguments); A function might take zero arguments (e.g, phpinfo(), which returns information on the PHP environment) or it might take several arguments (e.g, mail(), which takes three required and two optional arguments)
هنشرح الدوال بالتفصيل فيما بعد
______________________________________________________
Variables
المتغيرات هى اهم شىء فى اى لغه برمجه ولا توجد لغه برمجه فى العالم لا تحتوى على متغيرات
بس كل لغه برمجه ليها قواعد خاصه لكتابه المتغيرات بالنسبه للبى اتش بى لام يسبق لمتغير بعلامه الدولار وليس شرط ذكر نوعه لان البى اتش بى تتعرف تلقائى على نوعيه المتغير
$var_name = "Value";
وكأى لغه برمجه يوجد عده انواع للمتغيرات
| Variable Type | Explanation |
|---|---|
| Integer | whole number |
| Double | real number |
| String | string of characters |
| Boolean | true or false |
| Array | list of items |
| Object | instance of a class |
- قواعد كتابه المتغيرات كأى لغه برمجه ايضا باستثناء تعريف المتغير بوضع علامه الدولار
consist of letters, digits, underscores and dollar signs
cannot begin with a digit
are case sensitive
______________________________________ مثال
<?php $Greeting = 'Hello World!'; ?>
<html> <head> <title><?php echo $Greeting; ?></title> </head> <body> <?php echo $Greeting; ?> </body> </html>
_____________________________________________
Variable Scope
هى اللى بتحدد المكان اللى من خلاله اقدر استخدم المتغير
يعنى مثلا هل اقدر استخدم متغير تم تعريفه سابقا فى ملف اخر ولا لا؟؟
او هل اقدر استخدم متغير تم تعريفه فى داله ما قبل ذلك؟؟؟؟
للاجابه على هذه الاسئله نفهم اولا ايه انواع الفربل سكوب
| Variable Scope | Explanation |
|---|---|
| superglobal | Superglobal variables are predefined arrays, including $_POST and $_GET. They are accessible from anywhere on the page. |
| global | Global variables are visible throughout the script in which they are declared. However, they are not visible within functions in the script unless they are re-declared within the function as global variables. |
| function | Variables in the function scope are called local variables. Local variables are local to the function in which they are declared |
- _________________________________________________________
Superglobals
لازم نعرف الاول يعنى ايه
querystring
هذه الطريقة تكون بتمرير معلومات باستخدام ال
URL
القاعده العامه له
وهو العنوان الذي نقوم بكتابته في المتصفح للدخول على أي صفحة فمثلا للدخول على صفحة الفريق
https://phpcrew4learn.wordpress.com/
جذء من العنوان ويبدأ بعلامه استفهام
?
ويتم تعرف متغير يحتوى على الكلمات المحموله فى العنوان ويسمى المتغير ب
q
بحثت هنا فى جوجل عن كلمه المنصوره هتلاقيها محطوطه فى متغير اسمه كيو وده ثابت
واسم المتصفح ونوعه ونوع الترميز
نيجى بقى نكمل موضوعنا
ايه هى سوبر جلوبل
superglobal variables are predefined arrays, including $_POST and $_GET and are accessible from anywhere on the page.
ممكن تكون المتغيرات دى موجوده فى نفس الصفحه او فى صفحه اخرى ودى اشهر المستخدمين
- $_GET – variables passed into a page on the query string.
- $_POST – variables passed into a page through a form using the post method.
- $_SERVER – server environment variables (e.g, $_SERVER['HTTP_REFERER'] returns the URL of the referring page).
- $_COOKIE – cookie variables.
- $_FILES – variables containing information about uploaded files.
- $_ENV – PHP environment variables (e.g, $_ENV['HTTP_HOST'] returns the name of the host server.
- $_REQUEST – variables passed into a page through forms, the query string and cookies.
- $_SESSION – session variables.
لو انتا مثلا عامل فورمه تسجيل بيانات او اىفورم تستقبل فيها بيانات
اكيد لازم تستخدم المتيغيرات السوبر جلوبل لكى تحصل على اليبانات من الفورمه انها الوحيده اللى من خلالها تقدر تستخدمها من اى مكان وفى صفحه كانت مش شرط تكون فى نفس الصفحه
طب كده تمام اوى طيب
الشائع عندالناس عشان تحصل على اليبانات من الفورمه مثلا
3 طرق
| Style | Syntax (using $_GET) | Notes |
|---|---|---|
| Short | $varname |
|
| Medium | $_GET['varname'] |
|
| Long | $HTTP_GET_VARS['varname'] |
|
الطريقه التانيه هى الاكثر استخداما
ان شاء الله هنشرح بالتفصيل باقى السوبر جلوبل فى الدروس القادمه
__________________________________________
Constants
Constants are like variables except that, once assigned a value, they cannot be changed
define('CONST_NAME',VALUE);
Constants can be accessed from anywhere on the page.
____________________________________________
Variable-Testing and Manipulation Functions
PHP provides built-in functions for checking if a variable exists, checking if a variable holds a value, and removing a variable
مهم جدا جدا جدا
| Function | Explanation | Example |
|---|---|---|
| isset() | Checks to see if a variable exists. Returns true or false. | isset($a) |
| unset() | Removes a variable from memory. | unset($a) |
| empty() | Checks to see if a variable contains a non-empty, non-false value. | empty($a) |
هنشرح ان شاء الله تعالى كل الدوال فيما بعد بالتفصيل الممل
_______________________________________
PHP Operators
Arithmetic Operators
| Operator | Description | Example | Result |
|---|---|---|---|
| + | Addition | x=2 x+2 |
4 |
| - | Subtraction | x=2 5-x |
3 |
| * | Multiplication | x=4 x*5 |
20 |
| / | Division | 15/5 5/2 |
3 2.5 |
| % | Modulus (division remainder) | 5%2 10%8 10%2 |
1 2 0 |
| ++ | Increment | x=5 x++ |
x=6 |
| – | Decrement | x=5 x– |
x=4 |
Assignment Operators
| Operator | Example | Is The Same As |
|---|---|---|
| = | x=y | x=y |
| += | x+=y | x=x+y |
| -= | x-=y | x=x-y |
| *= | x*=y | x=x*y |
| /= | x/=y | x=x/y |
| .= | x.=y | x=x.y |
| %= | x%=y | x=x%y |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
| == | is equal to | 5==8 returns false |
| != | is not equal | 5!=8 returns true |
| <> | is not equal | 5<>8 returns true |
| > | is greater than | 5>8 returns false |
| < | is less than | 5<8 returns true |
| >= | is greater than or equal to | 5>=8 returns false |
| <= | is less than or equal to | 5<=8 returns true |
Logical Operators
| Operator | Description | Example |
|---|---|---|
| && | and | x=6 y=3(x < 10 && y > 1) returns true |
| || | or | x=6 y=3(x==5 || y==5) returns false |
| ! | not | x=6 y=3!(x==y) returns true |
other operators
| Operator | Name | Example |
|---|---|---|
?: |
Ternary |
$foo = ($age >= 18) ? 'adult' : 'child'; |
@ |
Error Suppression |
$a = @(1/0); |
| Operator | Name | Example |
|---|---|---|
. |
Concatenation |
$a . $b 'Hello' . ' world!' |
___________________________________________
Single Quotes vs. Double Quotes ‘ & “
عشان تطبع مثلا نص سترنج بسيط مش هتفرق تستخدم علامه التنصيص المفرده او المزدوجه لا فى النهايه ا لنتيجه واحده
اما لو عايز تزخرف النص بعمنى مثلا عايز تخليه نزل سطر جديد او يندمج مع اللى سيبقه معروف طبعا ان فيه رموز بنستخدها عشان تعمل كده
| Sequence | Meaning |
|---|---|
| \n | linefeed (LF or 0x0A (10) in ASCII) |
| \r | carriage return (CR or 0x0D (13) in ASCII) |
| \t | horizontal tab (HT or 0×09 (9) in ASCII) |
| \v | vertical tab (VT or 0x0B (11) in ASCII) (since PHP 5.2.5) |
| \f | form feed (FF or 0x0C (12) in ASCII) (since PHP 5.2.5) |
| \\ | backslash |
| \$ | dollar sign |
| \” | double-quote |
| \[0-7]{1,3} | the sequence of characters matching the regular expression is a character in octal notation |
| \x[0-9A-Fa-f]{1,2} | the sequence of characters matching the regular expression is a character in hexadecimal notation |
مشكلتنا بقى فى ان الزخرفه دى هتطبق بسفى حاله علامه التنصيص المزدوجه فقط
اما المفرده همثل لينا مشاكل كبيره
فالافضل هو علامه التنصيص المزدوجه لو عايز تزخرف النص
او حل احر برده
يعادل علامه التنصيص المزدوج بس بدون علامه تنصيص اسمه
Heredoc
A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline.
Example Heredoc string quoting example
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;/* More complex example, with variables. */class foo
{
var $foo;
var $bar;
function foo()
{
$this->foo = ’Foo’;
$this->bar = array(‘Bar1′, ’Bar2′, ’Bar3′);
}
}
$foo = new foo();
$name = ’MyName’;
echo <<<EOT
My name is ”$name”. I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital ’A': \x41
EOT;
?>
The above example will output:
My name is "MyName". I am printing some Foo. Now, I am printing some Bar2. This should print a capital 'A': A
________________________________________________________
