PHP PHP PHP HTML PHP PHP
PHP PHP PHP HTML PHP PHP
PHP PHP PHP HTML PHP PHP
ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ
ﺯﻣﺎﻥ)ﺳﺎﻋﺖ(
ﻋﻤﻠﻰ ﻧﻈﺮﻯ
12 6
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 118
ﻣﻘﺪﻣﻪ
ﺑﺮﺍﻱ ﺍﻳﺠﺎﺩ ﻓﺎﻳﻞﻫﺎﻱ PHPﻧﻴﺎﺯﻱ ﻧﻴﺴﺖ ﺣﺘﻤ ًﺎ ﺑﺮﻧﺎﻣﻪ ﺧﺎﺻﻲ ﺭﻭﻱ ﺳﻴﺴﺘﻢ ﻧﺼﺐ ﺷﻮﺩ ﻭ
ﻛﺪﻫﺎﻱ PHPﺭﺍ ﻣﻴﺘﻮﺍﻥ ﺩﺭ ﻳﻚ ﻭﻳﺮﺍﻳﺸﮕﺮ ﺳﺎﺩﻩ ﻣﺘﻨﻲ ﻣﺎﻧﻨﺪ Notepadﻧﻮﺷﺖ.
ﻧﺮﻡﺍﻓﺰﺍﺭ Dreamweaverﻧﻴﺰ ﻣﻲﺗﻮﺍﻧﺪ ﻓﺎﻳﻞﻫﺎﻱ PHPﺭﺍ ﭘﺸــﺘﻴﺒﺎﻧﻲ ﻛﺮﺩﻩ ﻭ ﻣﺤﻴﻂ ﻣﻨﺎﺳﺒﻲ
ﺑﺮﺍﻱ ﻛﺪﻧﻮﻳﺴﻲ ﻓﺮﺍﻫﻢ ﻛﻨﺪ.
ﺑﺮﺍﻱ ﻧﻮﺷــﺘﻦ ﺩﺳــﺘﻮﺭﺍﺕ PHPﺩﻭ ﺭﻭﺵ ﺍﺻﻠﻲ ﻭﺟﻮﺩ ﺩﺍﺭﺩ ﻛﻪ ﺩﺭ ﺍﺩﺍﻣﻪ ﺑﻪ ﺗﻮﺿﻴﺢ ﺁﻥﻫﺎ
ﺧﻮﺍﻫﻴﻢ ﭘﺮﺩﺍﺧﺖ .ﺷﻤﺎ ﺑﻪ ﺻﻮﺭﺕ ﺩﻟﺨﻮﺍﻩ ﻣﻲﺗﻮﺍﻧﻴﺪ ﻫﺮ ﻛﺪﺍﻡ ﺍﺯ ﺍﻳﻦ ﺳﺎﺧﺘﺎﺭﻫﺎ ﺭﺍ ﺩﺭ ﺑﺮﻧﺎﻣﻪ،
ﻣﻮﺭﺩ ﺍﺳﺘﻔﺎﺩﻩ ﻗﺮﺍﺭ ﺩﻫﻴﺪ.
• ﺭﻭﺵ ﺍﻭﻝ :ﺩﺳﺘﻮﺭﺍﺕ ﻭ ﻛﺪﻫﺎﻱ PHPﺩﺭﻭﻥ ﻋﻼﺋﻢ >? … ?< ﻗﺮﺍﺭ ﻣﻲﮔﻴﺮﻧﺪ.
?<
ﻛﺪﻫﺎﻱPHP ﺩﺳﺘﻮﺭﺍﺕ ﻭ
>?
<?phpﻗﺮﺍﺭ ﻣﻲﮔﻴﺮﻧﺪ. >? … • ﺭﻭﺵ ﺩﻭﻡ :ﺩﺳﺘﻮﺭﺍﺕ ﻭ ﻛﺪﻫﺎﻱ PHPﺩﺭﻭﻥ ﻋﻼﺋﻢ
<?php
ﻛﺪﻫﺎﻱPHP ﺩﺳﺘﻮﺭﺍﺕ ﻭ
>?
ﺑﺮﺍﻱ ﺍﻳﺠﺎﺩ ﻳﻚ ﻓﺎﻳﻞ ﺍﺟﺮﺍﻳﻲ ﺑﺴــﻴﺎﺭ ﺳــﺎﺩﻩ ﺩﺭ PHPﻣﺘــﻦ helloﺭﺍ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻧﻤﺎﻳﺶ
ﻣﻲﺩﻫﻴﻢ .ﺩﺭ ﺍﻧﺘﻬﺎﻱ ﻫﺮ ﺧﻂ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﻧﻴﺰ ﺑﺎﻳﺪ ﺍﺯ ﻋﻼﻣﺖ »;« ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ.
ﺑﺮﺍﻱ ﻧﻤﺎﻳﺶ ﺍﻃﻼﻋﺎﺕ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ،ﺩﺳﺘﻮﺭﺍﺕ ﻣﺨﺘﻠﻔﻲ ﺑﻪﻛﺎﺭ ﻣﻲﺭﻭﺩ ،ﺩﺳﺘﻮﺭ Printﻳﻜﻲ
ﺍﺯ ﭘﺮﻛﺎﺭﺑﺮﺩﺗﺮﻳﻦ ﺁﻥﻫﺎﺳﺖ .ﻛﺪ ﺯﻳﺮ ﻣﻴﺘﻮﺍﻧﺪ ﻣﺘﻦ helloﺭﺍ ﺩﺭ ﻣﺮﻭﺭﮔﺮ ﻧﻤﺎﻳﺶ ﺩﻫﺪ.
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
119 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
<? PHP
;)”!Print (”hello
>?
ﺍﻳﻦ ﻛﺪ ﺭﺍ ﺩﺭ Notepadﺑﻨﻮﻳﺴــﻴﺪ ،ﻓﺎﻳﻞ ﺭﺍ ﺑﺎ ﭘﺴــﻮﻧﺪ PHPﺩﺭ ﻣﺴﻴﺮ ﻧﺼﺐ WAMPﻭ ﺩﺭ
ﺷﺎﺧﻪ wwwﺫﺧﻴﺮﻩ ﻛﻨﻴﺪ.
ﺳﭙﺲ ﻣﺮﻭﺭﮔﺮ ﺭﺍ ﺑﺎﺯ ﻛﺮﺩﻩ ﻭ ﺩﺭ ﻧﻮﺍﺭ ﺁﺩﺭﺱ ﺍﻳﻦ ﻣﺘﻦ ﺭﺍ ﺗﺎﻳﭗ ﻛﻨﻴﺪ) :ﺑﻪ ﺟﺎﻱ ﻧﺎﻡ ﻓﺎﻳﻞ،
ﻋﻨﻮﺍﻧﻲ ﺭﺍ ﻛﻪ ﺑﺮﺍﻱ ﺫﺧﻴﺮﻩ ﻓﺎﻳﻞ ﻭﺍﺭﺩ ﻛﺮﺩﻳﺪ ﺩﺭﺝ ﻧﻤﺎﻳﻴﺪ(.
.phpﻧﺎﻡ ﻓﺎﻳﻞhttp://localhost/
ﺷﻜﻞ 6-1
ﻧﻜﺘﻪ ﺍﮔﺮ ﺍﻳﻦ ﻓﺎﻳﻞ ﺭﺍ ﺑﺎ ﻧﺎﻡ index.phpﻳﺎ default.phpﺫﺧﻴﺮﻩ ﻛﻨﻴﺪ ،ﻻﺯﻡ ﻧﻴﺴﺖ ﺩﺭ
ﻧﻮﺍﺭ ﺁﺩﺭﺱ ﻧﺎﻡ ﻓﺎﻳﻞ ﺭﺍ ﺫﻛﺮ ﻧﻤﺎﻳﻴﺪ ،ﻓﻘﻂ ﻛﺎﻓﻲ ﺍﺳﺖ ﻋﺒﺎﺭﺕ http://localhostﺭﺍ
ﺗﺎﻳﭗ ﻛﺮﺩﻩ ﻭ ﻛﻠﻴﺪ Enterﺭﺍ ﻓﺸﺎﺭ ﺩﻫﻴﺪ.
ﺩﺭ ﺗﻤﺎﻡ ﺳــﺎﻳﺖﻫﺎ ،ﺻﻔﺤﻪ ﺍﺻﻠﻲ ) (home pageﺳــﺎﻳﺖ ﺭﺍ ﺑﺎ ﻧﺎﻡ indexﻳﺎ defaultﺫﺧﻴﺮﻩ
ﻣﻴﻜﻨﻨﺪ ،ﻫﻨﮕﺎﻡ ﺩﺭﺝ ﺁﺩﺭﺱ ﻳﻚ ﺳــﺎﻳﺖ ،ﻫﻤﻴﺸﻪ ﺻﻔﺤﻪﺍﻱ ﻛﻪ ﺩﺭ ﻣﺴﻴﺮ ﺍﺻﻠﻲ ﺳﺎﻳﺖ ﺑﺎ ﻧﺎﻡ
indexﻳﺎ defaultﺑﺎﺷــﺪ ،ﺑﻪ ﻃﻮﺭ ﭘﻴﺶﻓﺮﺽ ﺑﺮﺍﻱ ﺍﺟﺮﺍ ﺍﻧﺘﺨﺎﺏ ﻣﻴﺸــﻮﺩ ،ﺳــﺎﻳﺮ ﺻﻔﺤﺎﺕ ﺍﺯ
ﻃﺮﻳﻖ ﻫﻤﻴﻦ ﺻﻔﺤﻪ ﺑﺎ ﻳﻜﺪﻳﮕﺮ ﻣﺮﺗﺒﻂ ﻣﻴﺸﻮﻧﺪ.
ﺩﺳﺘﻮﺭ ﺍﺻﻠﻲ ﺑﺮﺍﻱ ﭼﺎپ ﺍﻃﻼﻋﺎﺕ ﺩﺭ ﺧﺮﻭﺟﻲ ﻫﺮ ﺯﺑﺎﻥ ،PHPﺩﺳﺘﻮﺭ echoﺍﺳﺖ .ﺑﺮﻧﺎﻣﻪ
ﻗﺒﻞ ﺭﺍ ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﻲﺗﻮﺍﻧﻴﺪ ﺑﻪ ﺍﻳﻦ ﺻﻮﺭﺕ ﺑﻨﻮﻳﺴﻴﺪ:
<? Php
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 120
;)"!echo ("hello
>?
ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﺪ ﭼﻨﺪ ﻋﺒﺎﺭﺕ ﺭﺍ ﺗﻮﺳــﻂ ﻳﻚ ﺩﺳﺘﻮﺭ echoﭼﺎپ ﻛﻨﻴﺪ ،ﺑﺎﻳﺪ ﻫﺮ ﻋﺒﺎﺭﺕ ﺭﺍ ﺑﺎ
" ".ﺍﺯ ﻋﺒﺎﺭﺕ ﺑﻌﺪﻱ ﺟﺪﺍ ﻛﻨﻴﺪ .ﻣﺎﻧﻨﺪ)"echo ("hello!"." welcome
ﺣﺎﻝ ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﺪ ﻫﺮ ﻛﺪﺍﻡ ﺍﺯ ﻋﺒﺎﺭﺍﺕ ﺩﺭ ﻳﻚ ﺳﻄﺮ ﺟﺪﺍ ﭼﺎپ ﺷﻮﺩ ﺑﺎﻳﺪ ﺑﻴﻦ ﻫﺮ ﻋﺒﺎﺭﺕ
ﺍﺯ "> "<brﺍﺳﺘﻔﺎﺩﻩ ﻛﻨﻴﺪ.
)"echo ("hello!" . "<br>" . "welcome ﻣﺜﺎﻝ:
<?php
;)"!echo("hello
>?
></body
></html
ﻫﻤﺎﻧﻄﻮﺭ ﻛﻪ ﻣﻼﺣﻈﻪ ﻣﻲﻛﻨﻴﺪ ،ﺑﺮﺍﻱ ﺩﺭﺝ ﻛﺪ PHPﺩﺭﻭﻥ HTMLﻓﻘﻂ ﻛﺎﻓﻲ ﺍﺳﺖ ﺁﻥ ﺭﺍ
ﺩﺭﻭﻥ ﺗﮓ > <body> … </bodyﺑﻨﻮﻳﺴــﻴﺪ ،ﺍﻣﺎ ﭘﺲ ﺍﺯ ﻧﻮﺷﺘﻦ ﻛﺪﻫﺎ ،ﺑﺎﻳﺪ ﻓﺎﻳﻞ ﺑﺎ ﭘﺴﻮﻧﺪ .php
ﺫﺧﻴﺮﻩ ﺷﻮﺩ ﻭ ﺩﺭﺻﻮﺭﺕ ﺫﺧﻴﺮﻩ ﻓﺎﻳﻞ ﺑﺎ ﭘﺴﻮﻧﺪ htmﻳﺎ ،.htmlﻛﺪﻫﺎﻱ PHPﺍﺟﺮﺍ ﻧﺨﻮﺍﻫﻨﺪ ﺷﺪ.
ﺍﺳﺖ ﻛﻪ ﻣﻴﺨﻮﺍﻫﺪ ﺍﺯ ﻛﺪﻫﺎ ﺍﺳﺘﻔﺎﺩﻩ ﻛﻨﺪ ،ﺩﺭ PHPﻧﻴﺰ ﻣﺎﻧﻨﺪ ﺳﺎﻳﺮ ﺯﺑﺎﻥﻫﺎﻱ ﺑﺮﻧﺎﻣﻪﻧﻮﻳﺴﻲ
ﺩﺳــﺘﻮﺭﺍﻟﻌﻤﻞﻫﺎﻳﻲ ﺑﺮﺍﻱ ﺩﺭﺝ ﺗﻮﺿﻴﺤﺎﺕ ﻭﺟﻮﺩ ﺩﺍﺭﺩ .ﺩﺭ PHPﺑﺮﺍﻱ ﺗﻮﺿﻴﺤﺎﺕ ﻳﻚ ﺧﻄﻲ
ﺍﺯ ﻋﻼﺋــﻢ //ﻭ #ﻭ ﺑــﺮﺍﻱ ﺩﺭﺝ ﺗﻮﺿﻴﺤﺎﺕ ﭼﻨﺪ ﺧﻄﻲ ﺍﺯ ﻋﻼﻣﺖ * /ﺩﺭ ﺍﺑﺘﺪﺍ ﻭ ﺍﺯ ﻋﻼﻣﺖ*/
<?php
!/* Line number1: These 3 lines will not either
Line number2
Line number3: End of comment */
;)"!echo("hello
;)"!echo("welcome
# This line will not be parsed in PHP like the line above
>?
></body
></html
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 122
6-2ﻣﺘﻐﻴﺮﻫﺎ
ﻳﻜﻲ ﺍﺯ ﻣﻬﻤﺘﺮﻳﻦ ﺍﺑﺰﺍﺭﻫﺎﻳﻲ ﻛﻪ ﺑﺮﺍﻱ ﺗﺒﺪﻳﻞ ﺻﻔﺤﺎﺕ ﺳﺎﺩﻩ ﻭ ﺛﺎﺑﺖ ﺑﻪ ﺻﻔﺤﺎﺕ ﭘﻮﻳﺎ ﻻﺯﻡ
ﺍﺳﺖ ،ﺍﻳﻦ ﺍﺳﺖ ﻛﻪ ﺳﺮﻭﻳﺲﺩﻫﻨﺪﻩ ﺑﺘﻮﺍﻧﺪ ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺍﺯ ﻛﺎﺭﺑﺮ ﺳﺮﻭﻳﺲﮔﻴﺮﻧﺪﻩ ﺩﺭﻳﺎﻓﺖ ﻛﻨﺪ
ﻭ ﺑﺎ ﺗﻮﺟﻪ ﺑﻪ ﺍﻃﻼﻋﺎﺕ ﭘﺎﺳــﺦ ﻣﻨﺎﺳﺒﻲ ﺑﻪ ﻛﺎﺭﺑﺮ ﺑﺪﻫﺪ .ﻣﺘﻐﻴﺮﻫﺎ ﺍﺑﺰﺍﺭﻱ ﻫﺴﺘﻨﺪ ﻛﻪ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ
ﺍﺯ ﺁﻧﻬﺎ ﻣﻴﺘﻮﺍﻥ ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺍﺯ ﻛﺎﺭﺑﺮ ﺩﺭﻳﺎﻓﺖ ﻛﺮﺩ .ﺩﺭ ﻭﺍﻗﻊ ﻣﺘﻐﻴﺮﻫﺎ ﺑﻪ ﻣﻨﺰﻟﻪ ﻇﺮﻓﻬﺎﻳﻲ ﻫﺴﺘﻨﺪ
ﻛﻪ ﺍﻃﻼﻋﺎﺕ ﻛﺎﺭﺑﺮ ﺭﺍ ﺑﻪ ﻃﻮﺭ ﻣﻮﻗﺖ ﺫﺧﻴﺮﻩ ﻛﺮﺩﻩ ﻭ ﺩﺭ ﻣﻮﺍﻗﻊ ﻟﺰﻭﻡ ﺁﻧﺮﺍ ﺑﺮﺍﻱ ﺳﺮﻭﻳﺲﺩﻫﻨﺪﻩ
ﺍﺭﺳﺎﻝ ﻣﻴﻜﻨﻨﺪ.
ﺑﺮﺍﻱ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﺩﺭ PHPﺑﺎﻳﺪ ﺍﺯ ﺣﺮﻑ $ﺍﺳﺘﻔﺎﺩﻩ ﻛﺮﺩ.
;$a ﻣﺜﺎﻝ:
;$b=10
ﻧﻮﻉ ﻣﺘﻐﻴﺮ ﺩﺭ PHPﺍﻫﻤﻴﺘﻲ ﻧﺪﺍﺭﺩ ﻭ ﻻﺯﻡ ﻧﻴﺴﺖ ﻫﻨﮕﺎﻡ ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ،ﻧﻮﻉ ﺁﻥ ﺫﻛﺮ ﺷﻮﺩ.
ﻣﺘﻐﻴﺮﻫﺎﻱ PHPﻧﺴﺒﺖ ﺑﻪ ﺣﺮﻭﻑ ﻛﻮﭼﻚ ﻭ ﺑﺰﺭگ ﺣﺴﺎﺱ ﻫﺴﺘﻨﺪ.
ﺑــﻪ ﻋﻨﻮﺍﻥ ﻣﺜﺎﻝ ﻣﺘﻐﻴﺮﻫــﺎﻱ aﻭ Aﺑﺎ ﻳﻜﺪﻳﮕﺮ ﻣﺘﻔﺎﻭﺕ ﺑﻮﺩﻩ ﻭ ﺩﻭ ﻣﺘﻐﻴﺮ ﺟﺪﺍ ﻣﺤﺴــﻮﺏ
ﻣﻲﺷﻮﻧﺪ .ﺩﺭ ﻧﺎﻣﮕﺬﺍﺭﻱ ﻣﺘﻐﻴﺮﻫﺎ ﻋﻼﻭﻩ ﺑﺮ ﺣﺮﻭﻑ ﻛﻮﭼﻚ ﻭ ﺑﺰﺭگ ﻣﻲﺗﻮﺍﻥ ﺍﺯ ﻋﻼﺋﻤﻲ ﻣﺎﻧﻨﺪ
"_" ﻳﺎ ﺧﻂ ﻓﺎﺻﻠﻪ ﭘﺎﻳﻴﻦ ) (Underlineﺍﺳﺘﻔﺎﺩﻩ ﻛﺮﺩ.
ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻋﺪﺍﺩ ﻧﻴﺰ ﺩﺭ ﻧﺎﻣﮕﺬﺍﺭﻱ ﻣﺘﻐﻴﺮﻫﺎﻱ PHPﻣﺠﺎﺯ ﺍﺳﺖ ﺩﺭ ﺻﻮﺭﺗﻲﻛﻪ ﺍﻭﻟﻴﻦ ﺣﺮﻑ
ﺍﺯ ﻣﺘﻐﻴﺮ ﻧﺒﺎﺷﺪ.
ﻣﺜﺎﻝ :ﻣﺘﻐﻴﺮﻫﺎﻱ ﺑﺎ ﻧﺎﻡﻫﺎﻱ $ab_1ﻭ $_abcﻣﺠﺎﺯ ﻫﺴﺘﻨﺪ.
ﻣﺜﺎﻝ :ﻣﺘﻐﻴﺮﻫﺎﻱ ﺑﺎ ﻧﺎﻡﻫﺎﻱ $1abﻭ $1_aﻏﻴﺮﻣﺠﺎﺯ ﻫﺴﺘﻨﺪ.
ﻧﻜﺘﻪ ﻧﺎﻣﮕــﺬﺍﺭﻱ ﻣﺘﻐﻴﺮﻫﺎ ﺑﻪﻃﻮﺭﻱ ﻛﻪ "_" ) (Underlineﺩﺭ ﺍﺑﺘﺪﺍﻱ ﺁﻥﻫﺎ ﺑﺎﺷــﺪ ،ﻣﺠﺎﺯ
ﺍﺳــﺖ ﺍﻣﺎ ﺗﻮﺻﻴﻪ ﻣﻲﺷــﻮﺩ ﺍﺯ ﻧﺎﻣﮕﺬﺍﺭﻱ ﻣﺘﻐﻴﺮﻫﺎ ﺑﻪ ﺍﻳﻦ ﺷــﻴﻮﻩ ﺍﺳــﺘﻔﺎﺩﻩ ﻧﻜﻨﻴﺪ ﻭ
ﺣﺘﻲﺍﻻﻣﻜﺎﻥ ﺍﺯ "_" ﺩﺭ ﺍﺑﺘﺪﺍﻱ ﻧﺎﻡ ﻣﺘﻐﻴﺮﻫﺎ ﺍﺳﺘﻔﺎﺩﻩ ﻧﻜﻨﻴﺪ.
ﺩﺭ ﻣﺘﻐﻴﺮﻫﺎ ﻧﺸــﺎﻥ ﺩﺍﺩﻥ ﻧﻮﻉ ﺗﻮﺳــﻂ ﻣﻘﺪﺍﺭﺩﻫﻲ ﺗﻌﻴﻴﻦ ﻣﻲﺷﻮﺩ .ﺩﺳﺘﻮﺭﺍﻟﻌﻤﻞ ﺗﻌﻴﻴﻦ ﻧﻮﻉ
ﺑﺮﺍﻱ ﻫﺮ ﻣﺘﻐﻴﺮ ﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
• ﺍﻋﺪﺍﺩ ﺻﺤﻴﺢ ﺑﻪﻃﻮﺭ ﺳﺎﺩﻩ ﻧﻮﺷﺘﻪ ﻣﻲﺷﻮﻧﺪ.
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
123 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
;$a=15 ﻣﺜﺎﻝ:
• ﺍﻋﺪﺍﺩ ﺍﻋﺸﺎﺭﻱ ﺗﻮﺳﻂ ﻋﻼﻣﺖ" ".ﺗﻌﻴﻴﻦ ﻣﻲﺷﻮﻧﺪ.
ﻣﺜﺎﻝ:
;$b=7.0
;$C=1.295
• ﺍﻋﺪﺍﺩ ﻛﺴﺮﻱ ﺗﻮﺳﻂ ﻋﻼﻣﺖ " "/ﺗﻌﻴﻴﻦ ﻣﻲﺷﻮﻧﺪ.
;$f=1/2 ﻣﺜﺎﻝ:
0.5 ﻧﻜﺘﻪ ﺍﻋﺪﺍﺩ ﻛﺴﺮﻱ ﺑﻪﺻﻮﺭﺕ ﺍﻋﺸﺎﺭﻱ ﺫﺧﻴﺮﻩ ﻣﻲﺷﻮﻧﺪ ،ﺩﺭ ﻣﺜﺎﻝ ﻓﻮﻕ ﻣﺘﻐﻴﺮ fﺑﺎ
ﻣﻘﺪﺍﺭﺩﻫﻲ ﻣﻲﺷﻮﺩ.
ﺭﺷﺘﻪﻫﺎ ﺩﺭﻭﻥ ﻋﻼﻣﺖ " " ﻳﺎ ' ' ﺩﺭﺝ ﻣﻲﺷﻮﻧﺪ.
; "$Str = "Hello ﻣﺜﺎﻝ:
; "$H= "2914
; '$M = 'Welcome
ﺍﮔﺮ ﻳﻚ ﻋﺪﺩ ﺑﻴﻦ ﻋﻼﻣﺖ ” ” ﻗﺮﺍﺭ ﮔﻴﺮﺩ ،ﻣﻘﺪﺍﺭ ﺭﺷﺘﻪﺍﻱ ﻣﺤﺴﻮﺏ ﻣﻲﺷﻮﺩ.
ﻣﺜﺎﻝ :ﻣﻲﺧﻮﺍﻫﻴﻢ ﺍﺑﺘﺪﺍ ﺩﻭ ﻣﺘﻐﻴﺮ ﺭﺍ ﺑﺎ ﺍﻋﺪﺍﺩ 35ﻭ 79ﻣﻘﺪﺍﺭﺩﻫﻲ ﻛﻨﻴﻢ ،ﺳﭙﺲ ﺩﺭ ﺧﺮﻭﺟﻲ
ﺣﺎﺻﻞﺟﻤﻊ ﺍﻳﻦ ﺩﻭ ﻋﺪﺩ ﺭﺍ ﭼﺎپ ﻛﻨﻴﻢ:
><html
><head
><title>first program</title
></head
><body
<?php
;$num1 = 35
;$num2 = 79
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 124
>?
></body
></html
ﺷﻜﻞ 6-2
6-2-1ﺁﺭﺍﻳﻪﻫﺎ
ﻫﻤﺎﻥﻃــﻮﺭ ﻛﻪ ﻣﻲﺩﺍﻧﻴﺪ ﺁﺭﺍﻳﻪﻫﺎ ﺍﺯ ﻟﺤﺎﻅ ﺳــﺎﺧﺘﺎﺭﻱ ﭘﻴﭽﻴﺪﻩﺗﺮ ﺍﺯ ﺍﻧــﻮﺍﻉ ﺩﺍﺩﻩﻫﺎﻱ ﺩﻳﮕﺮ
ﻫﺴﺘﻨﺪ ،ﺑﺮﺧﻼﻑ ﺍﻧﻮﺍﻉ ﺩﺍﺩﻩﻫﺎﻱ ﺭﺷﺘﻪﺍﻱ ﻭ ﻋﺪﺩﻱ ﻛﻪ ﻓﻘﻂ ﻣﻲﺗﻮﺍﻧﻨﺪ ﻳﻚ ﻣﻘﺪﺍﺭ ﺭﺍ ﺑﭙﺬﻳﺮﻧﺪ،
ﺁﺭﺍﻳﻪﻫﺎ ﻣﻲﺗﻮﺍﻧﻨﺪ ﺷﺎﻣﻞ ﻟﻴﺴﺘﻲ ﺍﺯ ﻣﻘﺎﺩﻳﺮ ﻣﺨﺘﻠﻒ ﺑﺎﺷﻨﺪ.
ﺩﺭ ﺯﺑﺎﻥ PHPﺁﺭﺍﻳﻪﻫﺎ ﺭﺍ ﻣﻲﺗﻮﺍﻥ ﺑﻪ ﺩﻭ ﺩﺳــﺘﻪ ﺍﻧﺪﻳﺲﺩﺍﺭ 1ﻭ ﺍﻧﺠﻤﻨﻲ2ﺗﻘﺴﻴﻢ ﻛﺮﺩ ،ﺭﻭﺵ
ﺩﺳﺘﺮﺳﻲ ﺑﻪ ﻋﻨﺎﺻﺮ ﺩﺭ ﺍﻳﻦ ﺩﻭ ﺭﻭﺵ ﻣﺘﻔﺎﻭﺕ ﺍﺳﺖ.
ﺩﺭ ﺁﺭﺍﻳﻪﻫــﺎﻱ ﺍﻧﺪﻳﺲﺩﺍﺭ ،ﺩﺳﺘﺮﺳــﻲ ﺑﻪ ﻫﺮﻳــﻚ ﺍﺯ ﻋﻨﺎﺻﺮ ﺗﻮﺳــﻂ ﺍﻧﺪﻳﺲ ﺁﻥ ﺻﻮﺭﺕ
ﻣﻲﮔﻴﺮﺩ.
ﺍﻭﻟﻴﻦ ﺍﻧﺪﻳﺲ ﺁﺭﺍﻳﻪ ﻧﻴﺰ ﻣﺎﻧﻨﺪ ﺯﺑﺎﻥ ﺟﺎﻭﺍ ﺍﺳﻜﺮﻳﭙﺖ » «0ﺍﺳﺖ.
ﺳﺎﺧﺘﺎﺭ ﻛﻠﻲ ﺁﺭﺍﻳﻪ ﺍﻧﺪﻳﺲﺩﺍﺭ ﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
;“ﻣﻘﺪﺍﺭ ﻋﻨﺼﺮ ﺁﺭﺍﻳﻪ“= ] [ ﻧﺎﻡ ﻣﺘﻐﻴﺮ ﺁﺭﺍﻳﻪﺍﻱ $ ﻣﺜﺎﻝ:
;"$name[]="Maryam
;"$name[]="zahra
;"$name[]="Meisam
ﻣﺜﺎﻝ:
;) " "Meisamﻭ " "Zahraﻭ "$name = array ("Maryam
1- Indexed
2- Association
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
125 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
ﺣﺎﻝ ﻣﻲﺗﻮﺍﻧﻴﻢ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﻫﺮ ﻛﺪﺍﻡ ﺍﺯ ﻋﻨﺎﺻﺮ ﺁﺭﺍﻳﻪ ﺩﺳﺘﺮﺳﻲ ﺩﺍﺷﺘﻪ ﺑﺎﺷﻴﻢ.
ﺍﻧﺪﻳﺲ ﻋﻨﺎﺻﺮ ﺁﺭﺍﻳﻪ nameﺑﻪ ﺍﻳﻦ ﺻﻮﺭﺕ ﺑﺮﺍﻱ PHPﺷﻨﺎﺳﺎﻳﻲ ﻣﻲﺷﻮﻧﺪ:
"$name [0] = "Maryam
"$name [1] = "Zahra
"$name [2] = "Meisam
><html
><head
><title>first program</title
></head
><body
<?php
ﺷﻜﻞ 6-3
;)"$name= array("maryam","zahra","meisam
>?
></body
></html
ﺗﻤﺮﻳﻦ:
ﻳﻚ ﺁﺭﺍﻳﻪ ﻋﺪﺩﻱ ﺑﺎ 4ﻋﻨﺼﺮ ﺗﻌﺮﻳﻒﻛﻨﻴﺪ ،ﻋﻨﺎﺻﺮﺭﺍ ﺑﺎ ﺍﻋﺪﺍﺩ 9ﺗﺎ 5ﻣﻘﺪﺍﺭﺩﻫﻲﻛﺮﺩﻩ،
ﺳﭙﺲ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻧﺪﻳﺲ ﺁﺭﺍﻳﻪﻫﺎ ،ﺁﻥﻫﺎ ﺭﺍ ﺑﺎ ﻫﻢ ﺟﻤﻊ ﻛﺮﺩﻩ ،ﻧﺘﻴﺠﻪ ﺣﺎﺻﻞ ﺟﻤﻊ ﺭﺍ
ﺩﺭ ﺧﺮﻭﺟﻲ ﻧﻤﺎﻳﺶ ﺩﻫﻴﺪ.
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 126
6-2-3ﺛﺎﺑﺖﻫﺎ
ﻫﻤﺎﻥﮔﻮﻧﻪ ﻛﻪ ﺍﺯ ﻧﺎﻡ ﺛﺎﺑﺖﻫﺎ ﭘﻴﺪﺍﺳــﺖ ،ﻣﻘﺎﺩﻳﺮﻱ ﻫﺴﺘﻨﺪ ﻛﻪ ﺩﺭ ﻃﻮﻝ ﺍﺟﺮﺍﻱ ﺑﺮﻧﺎﻣﻪ ﺛﺎﺑﺖ
ﺑﻮﺩﻩ ﻭ ﻣﻘﺪﺍﺭ ﺁﻥﻫﺎ ﺗﻐﻴﻴﺮ ﻧﻤﻲﻛﻨﺪ.
ﺛﺎﺑﺖﻫﺎ ﺑﻪﻃﻮﺭ ﺳﺮﺍﺳﺮﻱ ﻭ ﺩﺭ ﻫﻤﻪ ﺟﺎﻱ ﺑﺮﻧﺎﻣﻪ ﻗﺎﺑﻞ ﺍﺳﺘﻔﺎﺩﻩ ﻭ ﺩﺭ ﺩﺳﺘﺮﺱ ﻫﺴﺘﻨﺪ.
ﺑﺮﺍﻱ ﺗﻌﺮﻳﻒ ﺛﺎﺑﺖﻫﺎ ﺍﺯ ﺗﺎﺑﻊ defineﺍﺳﺘﻔﺎﺩﻩ ﻣﻲﺷﻮﺩ ﻭ ﻧﻴﺎﺯ ﺑﻪ ﺩﺭﺝ ﻋﻼﻣﺖ $ﻧﺪﺍﺭﻧﺪ.
ﻫﻨﮕﺎﻡ ﺍﺳــﺘﻔﺎﺩﻩ ﺍﺯ ﺛﺎﺑﺖﻫﺎ ﺩﺭ ﻃﻮﻝ ﺑﺮﻧﺎﻣﻪ ﻧﻴﺰ ﺑﻪ ﻋﻼﻣﺖ $ﻧﻴﺎﺯ ﻧﺪﺍﺷﺘﻪ ﻭ ﺗﻨﻬﺎ ﻧﻮﺷﺘﻦ ﻧﺎﻡ
ﻣﺘﻐﻴﺮ ﻛﺎﻓﻲ ﺍﺳﺖ.
ﺳﺎﺧﺘﺎﺭ ﻛﻠﻲ ﺗﻌﺮﻳﻒ ﺛﺎﺑﺖﻫﺎ ﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
ﻣﺜﺎﻝ:
; )"ﻣﻘﺪﺍﺭ ﺛﺎﺑﺖ"",ﻧﺎﻡ ﺛﺎﺑﺖ"( define
; )"define("PI","3.14
ﻣﺜــﺎﻝ ﺯﻳﺮ ﻋﺪﺩ 3/14ﺭﺍ ﺩﺭ ﻣﺘﻐﻴﺮﻱ ﺑﻪ ﻧﺎﻡ piﺑﻪﻃﻮﺭ ﺛﺎﺑﺖ ﻗﺮﺍﺭ ﻣﻲﺩﻫﺪ ،ﺷــﻌﺎﻉ ﺩﺍﻳﺮﻩ ﺭﺍ
ﻣﺘﻐﻴﺮﻱ ﺻﺤﻴﺢ ﻭ ﺑﺎ ﻋﺪﺩ 5ﻣﻘﺪﺍﺭﺩﻫﻲ ﻣﻲﻛﻨﺪ ،ﺳــﭙﺲ ﻣﺤﻴﻂ ﺩﺍﻳﺮﻩ ﺭﺍ ﻣﺤﺎﺳــﺒﻪ ﻛﺮﺩﻩ ﻭ ﺩﺭ
ﺧﺮﻭﺟﻲ ﻧﺸﺎﻥ ﻣﻲﺩﻫﺪ.
<?php
;)"define ("pi","3.14
;$r=5
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
127 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
;"$e=pi*2*"$r
>?
ﺷﻜﻞ 6-4
6-3ﻋﻤﻠﮕﺮﻫﺎ
6-3-1ﻋﻤﻠﮕﺮﻫﺎﻱ ﻣﺤﺎﺳﺒﺎﺗﻲ
ﻋﻤﻠﮕﺮﻫﺎ ﺩﺭ ﺗﻤﺎﻡ ﺯﺑﺎﻥﻫﺎ ﺑﺮﺍﻱ ﺍﺟﺮﺍﻱ ﻣﺤﺎﺳﺒﺎﺕ ﺭﻭﻱ ﺩﺍﺩﻩﻫﺎ ﺑﻪﻛﺎﺭ ﻣﻲﺭﻭﻧﺪ.
ﺟﺪﻭﻝ 6-1
ﻣﺜﺎﻝ ﻋﻤﻠﮕﺮ
$a+$b ﺟﻤﻊ +
6-3-2ﻋﻤﻠﮕﺮﻫﺎﻱ ﻣﻘﺎﻳﺴﻪﺍﻱ
ﺟﺪﻭﻝ 6-2
ﻣﺜﺎﻝ ﻋﻤﻠﮕﺮ
$a == $b ﺗﺴﺎﻭﻱ ==
ﺑﺎ ﻫﻢ ﻣﺴــﺎﻭﻱ ﻫﺴــﺘﻨﺪ ﻳﺎ ﺧﻴﺮ، $aﻭ$b ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﺪ ﻣﺸــﺨﺺ ﻛﻨﻴﺪ ﻛﻪ ﺁﻳﺎ ﺩﻭ ﻣﺘﻐﻴﺮ
ﻣﻲﺗﻮﺍﻧﻴﺪ ﺍﺯ ﻋﻤﻠﮕﺮ == ﺍﺳﺘﻔﺎﺩﻩ ﻛﻨﻴﺪ.
;1. $a= 5 ﻣﺜﺎﻝ :1
;2. $b=5
;3.$c=10
;4. $a == $b
;5.$b==$c
ﺩﺭ ﺩﺳﺘﻮﺭ ﺳﻄﺮ 4ﭼﻮﻥ $aﺑﺎ $bﺑﺮﺍﺑﺮ ﻫﺴﺘﻨﺪ ﻣﻘﺪﺍﺭ trueﺑﺮﮔﺮﺩﺍﻧﺪﻩ ﻣﻲﺷﻮﺩ.
ﺍﻣﺎ ﺩﺭ ﺳــﻄﺮ 5ﺑﻪ ﺩﻟﻴﻞ ﺍﻳﻦﻛﻪ $cﻭ $bﺑﺎ ﻫﻢ ﻣﺴــﺎﻭﻱ ﻧﻴﺴــﺘﻨﺪ ﻣﻘــﺪﺍﺭ falseﺑﺮﮔﺮﺩﺍﻧﺪﻩ
ﻣﻲﺷﻮﺩ.
ﻣﺜﺎﻝ :2
;$a = 3
;"$b = "3
;$a == $b
ﻧﻮﻉ ﺭﺷﺘﻪﺍﻱ ﺑﻪ ﻧﻮﻉ ﺩﺭ ﺩﺳــﺘﻮﺭ ﺳــﻮﻡ ﺍﺭﺯﺵ trueﺑﺮﮔﺮﺩﺍﻧﺪﻩ ﻣﻲﺷﻮﺩ ﺯﻳﺮﺍ ﺍﺑﺘﺪﺍ ﻣﺘﻐﻴﺮ$b
ﻋﺪﺩﻱ ﺗﺒﺪﻳﻞ ﻣﻲﺷﻮﺩ ﻭ ﺳﭙﺲ ﻣﻘﺎﻳﺴﻪ ﺻﻮﺭﺕ ﻣﻲﮔﻴﺮﺩ.
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
129 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﻢ ﺗﺒﺪﻳﻞ ﻧﻮﻉ ﺻﻮﺭﺕ ﻧﮕﻴﺮﺩ ﻭ ﻣﻘﺎﻳﺴﻪ ﺑﺎ ﺍﻧﻮﺍﻉ ﻳﻜﺴﺎﻥ ﺻﻮﺭﺕ ﮔﻴﺮﺩ ،ﺑﺎﻳﺪ
;$a= 7 ﺍﺯ ﻋﻤﻠﮕﺮ === ﺍﺳﺘﻔﺎﺩﻩ ﻛﻨﻴﻢ:
;"$b = "7
;$a === $b
ﺭﺍ ﺑﺮﻣﻲﮔﺮﺩﺍﻧﺪ ،ﺯﻳﺮﺍ $aﻭ $bﻫﻤﻨﻮﻉ ﻧﻴﺴﺘﻨﺪ. ﻣﻘﺪﺍﺭfalse ﺩﺳﺘﻮﺭ ﺳﻮﻡ
6-3-3ﻋﻤﻠﮕﺮﻫﺎﻱ ﻣﻨﻄﻘﻲ
ﻋﻤﻠﮕﺮﻫــﺎﻱ ﻣﻨﻄﻘــﻲ ﺭﻭﻱ ﻋﺒﺎﺭﺍﺕ ﻣﻨﻄﻘﻲ ﻋﻤﻞ ﻣﻲﻛﻨﻨﺪ .ﺑﻪ ﻋﻨــﻮﺍﻥ ﻣﺜﺎﻝ ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﻢ
ﺗﺸــﺨﻴﺺ ﺩﻫﻴﻢ ﻣﻘﺪﺍﺭ ﻣﺘﻐﻴﺮ $aﺑﻴﻦ 1ﻭ 100ﻗﺮﺍﺭ ﺩﺍﺭﺩ ﺑﺎﻳﺪ ﺍﺯ ﻋﻤﻠﮕﺮﻫﺎﻱ ﻣﻨﻄﻘﻲ ﺍﺳﺘﻔﺎﺩﻩ
ﻛﻨﻴﻢ .ﺍﻳﻦ ﻋﻤﻠﮕﺮﻫﺎ ﺭﺍ ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﻣﺸﺎﻫﺪﻩ ﻣﻲﻧﻤﺎﻳﻴﺪ:
ﺟﺪﻭﻝ 6-3
ﻧﺘﻴﺠﻪ ﻣﺜﺎﻝ ﻧﺎﻡ ﻋﻤﻠﮕﺮ
ﺍﮔﺮ $bﻧﺎﺩﺭﺳﺖ ﺑﺎﺷﺪ ،ﻧﺘﻴﺠﻪ ﺩﺭﺳﺖ ﺍﺳﺖ ﻭ ﺑﺮﻋﻜﺲ. $b ﻧﻘﻴﺾ )(NOT |
ﺍﮔﺮ $aﻭ $bﻫﺮ ﺩﻭ ﺩﺭﺳﺖ ﺑﺎﺷﻨﺪ ﻧﺘﻴﺠﻪ ﺩﺭﺳﺖ ﺍﺳﺖ ﺩﺭ
$a && $bﻏﻴﺮ ﺍﻳﻦﺻﻮﺭﺕ ﻧﺎﺩﺭﺳﺖ ﺍﺳﺖ. ﻭ )(AND &&
6-3-4ﻋﻤﻠﮕﺮﻫﺎﻱ ﺗﺮﻛﻴﺒﻲ
ﺗﻌﺪﺍﺩﻱ ﺍﺯ ﻋﻤﻠﮕﺮﻫﺎ ﺩﺭ PHPﻭﺟﻮﺩ ﺩﺍﺭﻧﺪ ﻛﻪ ﺗﺮﻛﻴﺒﻲ ﺍﺯ ﺩﻭ ﻋﻤﻠﮕﺮ ﺩﻳﮕﺮ ﻫﺴﺘﻨﺪ ﻭ ﺑﻪ ﻧﺎﻡ
ﻋﻤﻠﮕﺮﻫﺎﻱ ﺗﺮﻛﻴﺒﻲ ﺧﻮﺍﻧﺪﻩ ﻣﻲﺷﻮﻧﺪ .ﺍﻳﻦ ﻋﻤﻠﮕﺮﻫﺎ ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﺗﻮﺿﻴﺢ ﺩﺍﺩﻩ ﺷﺪﻩﺍﻧﺪ:
ﺟﺪﻭﻝ 6-4
ﻋﺒﺎﺭﺕ ﻣﻌﺎﺩﻝ ﻣﺜﺎﻝ ﻧﺎﻡ ﻋﻤﻠﮕﺮ
$a = $a + $b $a += $b ﺍﻧﺘﺴﺎﺏ ﺟﻤﻊ =+
6-3-5ﻋﻤﻠﮕﺮﻫﺎﻱ ﺭﺷﺘﻪﺍﻱ
ﻳﻜﻲ ﺍﺯ ﭘﺮﺍﺳــﺘﻔﺎﺩﻩﺗﺮﻳﻦ ﻋﻤﻠﻴﺎﺗﻲ ﻛﻪ ﺭﻭﻱ ﺭﺷــﺘﻪﻫﺎ ﺍﻧﺠﺎﻡ ﻣﻲﮔﻴــﺮﺩ ,ﻋﻤﻞ ﺍﻟﺤﺎﻕ ﻛﺮﺩﻥ
ﺭﺷﺘﻪﻫﺎﺳﺖ .ﺑﻪ ﻋﻤﻞ ﭼﺴﺒﺎﻧﺪﻥ ﺩﻭ ﺭﺷﺘﻪ ﺑﻪ ﻳﻜﺪﻳﮕﺮ ﻋﻤﻞ ﺍﻟﺤﺎﻕ ﺭﺷﺘﻪﻫﺎ ﮔﻔﺘﻪ ﻣﻲﺷﻮﺩ.
ﺑﻪ ﻋﻨﻮﺍﻥ ﻣﺜﺎﻝ ﺩﻭ ﺭﺷﺘﻪ ﺯﻳﺮ ﺭﺍ ﺩﺭ ﻧﻈﺮ ﺑﮕﻴﺮﻳﺪ.
;"$a="web
;"$b="design
ﺍﮔﺮ ﺭﺷــﺘﻪﺍﻱ ﺩﺭ ﻧﻘﻞ ﻗﻮﻝ ﺩﻭﺗﺎﻳﻲ ﻗﺮﺍﺭ ﮔﻴﺮﺩ PHP ،ﺳﻌﻲ ﻣﻲﻛﻨﺪ ﺁﻥ ﺭﺍ ﻣﺜﻞ ﻳﻚ ﻋﺒﺎﺭﺕ
ﺍﺭﺯﻳﺎﺑﻲ ﻛﻨﺪ ،ﻭﻟﻲ ﺍﮔﺮ ﺭﺷﺘﻪ ﺩﺭ ﻧﻘﻞ ﻗﻮﻝ ﻳﻜﺎﻧﻲ ﻗﺮﺍﺭ ﮔﻴﺮﺩ ،ﺍﺭﺯﻳﺎﺑﻲ ﻧﻤﻲﺷﻮﺩ .ﺑﺮﺍﻱ ﻣﺜﺎﻝ ﺑﻪ
ﺩﺳﺘﻮﺭﺍﺕ ﺯﻳﺮ ﻧﮕﺎﻩ ﻛﻨﻴﺪ:
;1.$a=10
;"2.echo "value of $a
;'3.echo 'value of $a
ﺩﺳــﺘﻮﺭ ﺳــﻄﺮ ﺍﻭﻝ ﻣﻘﺪﺍﺭ 10ﺭﺍ ﺩﺭ ﻣﺘﻐﻴﺮ $aﻗﺮﺍﺭ ﻣﻲﺩﻫﺪ .ﺧﺮﻭﺟﻲ ﺩﺳــﺘﻮﺭ ﺳﻄﺮ ﺩﻭﻡ
ﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
Value of 10
ﺩﺭ ﻣﺒﺤﺚ ﺟﺎﻭﺍ ﺍﺳﻜﺮﻳﭙﺖ ﺑﺎ ﺳﺎﺧﺘﺎﺭﻫﺎﻱ ﻛﻨﺘﺮﻟﻲ ﺁﺷﻨﺎ ﺷﺪﻳﺪ ،ﺩﺭ ﺍﻳﻦ ﻗﺴﻤﺖ ﺿﻤﻦ ﺑﻴﺎﻥ
ﻧﻜﺎﺕ ﻣﺨﺘﺼﺮﻱ ﺟﻬﺖ ﻳﺎﺩﺁﻭﺭﻱ ﻣﻄﺎﻟﺐ ،ﺑﻪ ﺑﺮﺭﺳﻲ ﺳﺎﺧﺘﺎﺭ ﻫﺮ ﻛﺪﺍﻡ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﺩﺭ ﺯﺑﺎﻥ
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
131 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
PHPﻣﻲﭘﺮﺩﺍﺯﻳﻢ:
6-4-1ﺩﺳﺘﻮﺭ if
ﻭﺍﺭﺩ ﺑﻠﻮﻙ ﻛﺪ ﻣﺮﺑﻮﻁ ﺑﻪ ﭘﺎﺳﺦtrue ﻳﻚ ﻋﺒﺎﺭﺕ ﺭﺍ ﺑﺮﺭﺳــﻲ ﻣﻲﻛﻨﺪ ،ﺩﺭ ﺻﻮﺭﺕ ﺩﺍﺷﺘﻦ
ifﻣﻲﺷﻮﺩ ،ﺩﺭ ﻏﻴﺮ ﺍﻳﻦﺻﻮﺭﺕ ﺍﺯ ﺑﻠﻮﻙ ifﻣﻲﮔﺬﺭﺩ.
ﺳﺎﺧﺘﺎﺭ ﺩﺳﺘﻮﺭ ifﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
ﺷﺮﻃﻲ(if )ﻋﺒﺎﺭﺕ
{
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ ﺩﺭ ﭘﺮﺍﻧﺘﺰ ﻣﻘﺎﺑﻞ ﺩﺳﺘﻮﺭ ifﺑﺎﻳﺪ ﻳﻚ ﻋﺒﺎﺭﺕ ﺷﺮﻃﻲ ﮔﺬﺍﺷﺘﻪ ﺷﻮﺩ.
}
ﻣﺜﺎﻝ:
><html
><head
><title>Listing 5.1</title
></head
><body
<?php
;"$a = "hello
) "if ( $a == "hello
{
;"echo "hello... welcome
}
>?
></body
></html
ﺍﮔﺮ ﺑﺨﻮﺍﻫﻴﻢ ﺩﺳﺘﻮﺭ ifﺭﺍ ﻃﻮﺭﻱ ﺑﻨﻮﻳﺴﻴﻢ ﻛﻪ ﺩﺭ ﺻﻮﺭﺕ ﺑﺮﻗﺮﺍﺭ ﻧﺒﻮﺩﻥ ﺷﺮﻁ ﺍﻭﻝ ،ﺷﺮﻁ
ﺩﻭﻡ ،ﺳــﻮﻡ ﻭ ...ﺑﺮﺭﺳﻲ ﺷﻮﺩ ﻭ ﺩﺭ ﺻﻮﺭﺕ ﺻﺤﻴﺢ ﺑﻮﺩﻥ ﻫﺮ ﻛﺪﺍﻡ ﻛﺪﻫﺎﻱ ﻣﺨﺼﻮﺹ ﺁﻥ
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 132
else
}
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ
}
ﺩﺭ ﺳــﺎﺧﺘﺎﺭ ﻓﻮﻕ ﺍﺑﺘﺪﺍ ﺷﺮﻁ ﻣﻘﺎﺑﻞ ifﭼﻚ ﻣﻲﺷﻮﺩ ،ﺍﮔﺮ ﺩﺭﺳﺖ ﺑﻮﺩ ،ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ ﺁﻥ
ﺍﺟﺮﺍ ﻣﻲﺷﻮﺩ ،ﺍﻣﺎ ﺍﮔﺮ ﻧﺎﺩﺭﺳﺖ ﺑﻮﺩ ﺷﺮﻁ ﻣﻘﺎﺑﻞ elseifﺍﻭﻝ ﺍﺟﺮﺍ ﻣﻲﺷﻮﺩ ،ﺩﺭ ﺻﻮﺭﺕ ﺻﺤﻴﺢ
ﺑﻮﺩﻥ ،ﻛﺪﻫﺎﻱ ﺁﻥ ﺍﺟﺮﺍ ﺷــﺪﻩ ،ﺍﻣﺎ ﺍﮔﺮ ﺻﺤﻴﺢ ﻧﺒﺎﺷــﺪ ،ﺩﺳــﺘﻮﺭﺍﺕ elseifﺑﻌﺪﻱ ﺭﺍ ﺑﺮﺭﺳــﻲ
ﻣﻲﻛﻨﺪ ﻭ ﺍﻳﻦ ﻋﻤﻞ ﺑﻪ ﺗﻌﺪﺍﺩ ﺩﺳﺘﻮﺭﺍﺕ elseifﺍﺩﺍﻣﻪ ﭘﻴﺪﺍ ﻣﻲﻛﻨﺪ ﻭ ﺩﺭ ﻧﻬﺎﻳﺖ ﺍﮔﺮ ﻫﻴﭻﻛﺪﺍﻡ ﺍﺯ
ﺷﺮﻁﻫﺎﻱ ifﻭ elseifﺻﺤﻴﺢ ﻧﺒﻮﺩﻧﺪ ،ﺩﺳﺘﻮﺭﺍﺕ ﻣﺮﺑﻮﻁ ﺑﻪ ﺑﺪﻧﻪ elseﺍﺟﺮﺍ ﻣﻲﮔﺮﺩﺩ.
ﻣﺜﺎﻝ:
><html
><head
><title>Listing 5.3</title
></head
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
133 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
><body
<?php
;"$mood = "sad
) "if ( $mood == "happy
{
;"echo "Hooray, I'm in a good mood
}
) "elseif ( $mood =="sad
{
;"!echo " I'm in a bad mood
}
else
{
;"echo "Neither happy nor sad but $mood
}
>?
></body
></html
ﭘﺲ ﺍﺯ ﺍﺟﺮﺍﻱ ﻛﺪ ﻣﻮﺭﺩ ﻧﻈﺮ ﻣﺸــﺎﻫﺪﻩ ﻣﻲﻛﻨﻴﺪ ﻛﻪ ﺑﻪ ﺩﻟﻴﻞ ﺩﺭﺳــﺖ ﺑﻮﺩﻥ ﺷــﺮﻁ ﻣﻘﺎﺑﻞ
،elseifﺩﺳﺘﻮﺭﺍﺕ ﻣﺮﺑﻮﻁ ﺑﻪ ﺍﻳﻦ ﺑﻠﻮﻙ ﺍﺟﺮﺍ ﻣﻲﺷﻮﺩ.
ﺷﻜﻞ6-5
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 134
ﺗﻤﺮﻳﻦ:
ﺩﺳﺘﻮﺭﺍﺕ ﻓﻮﻕ ﺭﺍ ﻃﻮﺭﻱ ﺗﻐﻴﻴﺮ ﺩﻫﻴﺪ ﻛﻪ ﺑﻠﻮﻙ ﻣﺮﺑﻮﻁ ﺑﻪ elseﺍﺟﺮﺍ ﺷﻮﺩ.
6-4-2ﺩﺳﺘﻮﺭSwitch
ﺳﺎﺧﺘﺎﺭ ﻛﻠﻲ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﺎﻧﻨﺪ ﺟﺎﻭﺍ ﺍﺳﻜﺮﻳﭙﺖ ﺍﺳﺖ:
Switch )ﻧﺎﻡ ﻣﺘﻐﻴﺮ(
{
ﺩﻭﻡCase :ﻣﻘﺪﺍﺭ
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ
;break
.........
default
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ
}
ﺩﺭ ﺳــﺎﺧﺘﺎﺭ Switchﻣﻘﺪﺍﺭ ﻣﺘﻐﻴﺮ ﻣﻘﺎﺑﻞ Switchﺑﺎ ﻣﻘﺎﺩﻳﺮ ﻣﻘﺎﺑﻞ Caseﻫﺎ ﻣﻘﺎﻳﺴﻪ ﻣﻲﺷﻮﺩ،
ﺍﮔﺮ ﺑﺎ ﻣﻘﺪﺍﺭ ﻣﻘﺎﺑﻞ Caseﺍﻭﻝ ﺑﺮﺍﺑﺮ ﺑﺎﺷﺪ ،ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ ﺁﻥ ﺍﺟﺮﺍ ﻣﻲﺷﻮﺩ ﻭ ﺳﭙﺲ ﺍﺯ ﺑﻠﻮﻙ
Switchﺧﺎﺭﺝ ﻣﻲﺷــﻮﺩ ،ﺍﮔﺮ ﺑﺮﺍﺑﺮ ﺑﺎ ﻣﻘﺪﺍﺭ ﻣﻘﺎﺑﻞ Caseﺩﻭﻡ ﺑﺎﺷــﺪ ،ﺩﺳﺘﻮﺭﺍﺕ ﻣﺮﺑﻮﻁ ﺑﻪ ﺁﻥ
ﺍﺟﺮﺍ ﺷﺪﻩ ﻭ ﺍﺯ ﺑﻠﻮﻙ Switchﺧﺎﺭﺝ ﻣﻲﺷﻮﺩ.
ﺑــﻪ ﻫﻤﻴﻦ ﺗﺮﺗﻴﺐ ﭼﻚ ﻛﺮﺩﻥ ﻣﻘﺎﺩﻳﺮ ﺍﺩﺍﻣﻪ ﭘﻴﺪﺍ ﻣﻲﻛﻨﺪ ﻭ ﺍﮔﺮ ﻫﻴﭻﻛﺪﺍﻡ ﺍﺯ ﻣﻘﺎﺩﻳﺮ ﺑﺮﺍﺑﺮ ﺑﺎ
ﻣﺘﻐﻴﺮ ﻣﻘﺎﺑﻞ Switchﻧﺒﻮﺩﻧﺪ ،ﺩﺳﺘﻮﺭ ﺑﺪﻧﻪ defaultﺍﺟﺮﺍ ﻣﻲﺷﻮﺩ.
ﻣﺜﺎﻝ ﻗﺒﻞ ﻣﺮﺑﻮﻁ ﺑﻪ ﺷﺮﻁ if … elseifﺭﺍ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺩﺳﺘﻮﺭ Switchﺑﺎﺯﻧﻮﻳﺴﻲ ﻣﻲﻛﻨﻴﻢ:
><html
><head
><title>Listing 5.4</title
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
135 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
></head
><body
<?php
;"$mood = "sad
) switch ( $mood
{
case "happy":
;"echo "Hooray, I'm in a good mood
;break
case "sad":
;"!echo "I'm in a bad mood
;break
default:
;"echo "Neither happy nor sad but $mood
}
>?
></body
></html
ﭘﺲ ﺍﺯ ﺍﺟﺮﺍﻱ ﻛﺪ ﻓﻮﻕ ﺧﺮﻭﺟﻲ ﺍﻳﻦ ﺑﺮﻧﺎﻣﻪ ﻧﻴﺰ ﻣﺸﺎﺑﻪ ﺷﻜﻞ 5-5ﺧﻮﺍﻫﺪ ﺑﻮﺩ.
6-5ﺣﻠﻘﻪﻫﺎ
ﺣﻠﻘﻪﻫﺎ ﻳﻜﻲ ﺩﻳﮕﺮ ﺍﺯ ﺍﻣﻜﺎﻧﺎﺕ ﺯﺑﺎﻥﻫﺎﻱ ﺑﺮﻧﺎﻣﻪﻧﻮﻳﺴﻲ ﻫﺴﺘﻨﺪ ﻛﻪ ﺍﺟﺎﺯﻩ ﻣﻲﺩﻫﻨﺪ ﺩﺳﺘﻮﺭ
ﻳﺎ ﺩﺳﺘﻮﺭﺍﺗﻲ ﭼﻨﺪ ﺑﺎﺭ ﺍﺟﺮﺍ ﺷﻮﻧﺪ.
6-5-1ﺩﺳﺘﻮﺭ for
ﺳﺎﺧﺘﺎﺭ ﻛﻠﻲ ﺩﺳﺘﻮﺭ forﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
)ﻣﻴﺰﺍﻥ ﺍﻓﺰﺍﻳﺶ ﻳﺎ ﻛﺎﻫﺶ ﻣﺘﻐﻴﺮ ; ﻋﺒﺎﺭﺕ ﺷﺮﻃﻲ ; ﻣﻘﺪﺍﺭ ﺍﻭﻟﻴﻪ ﺣﻠﻘﻪ( for
{
ﺑﺪﻧﻪ ﺣﻠﻘﻪ
}
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 136
ﺗﻤﺮﻳﻦ:
ﺑﺎ ﺍﺳــﺘﻔﺎﺩﻩ ﺍﺯ ﺣﻠﻘﻪ forﺑﺮﻧﺎﻣﻪﺍﻱ ﺑﻨﻮﻳﺴﻴﺪ ﻛﻪ ﺍﻋﺪﺍﺩ 100ﺗﺎ 50ﺭﺍ ﺑﻪﺻﻮﺭﺕ ﻧﺰﻭﻟﻲ
ﺩﺭ ﺧﺮﻭﺟﻲ ﭼﺎپ ﻛﻨﺪ.
ﺩﺭ ﺳــﺎﺧﺘﺎﺭ ﺣﻠﻘــﻪ forﻣﺎﻧﻨﺪ ﺟﺎﻭﺍ ﺍﺳــﻜﺮﻳﭙﺖ ﻣﻲﺗﻮﺍﻥ ﻣﻘﺪﺍﺭ ﺍﻭﻟﻴــﻪ ﺣﻠﻘﻪ ﺭﺍ ﻗﺒﻞ ﺍﺯ for
ﻣﻘﺪﺍﺭﺩﻫــﻲ ﻛﺮﺩ ﻭ ﺍﺯ ﻧﻮﺷــﺘﻦ ﺁﻥ ﻣﻘﺎﺑﻞ forﺻﺮﻑﻧﻈﺮ ﻛﺮﺩ ،ﻫﻢﭼﻨﻴــﻦ ﺍﺯ ﻣﻴﺰﺍﻥ ﺍﻓﺰﺍﻳﺶ ﻳﺎ
ﻛﺎﻫﺶ ﻣﺘﻐﻴﺮ ﻛﻪ ﻣﻌﻤﻮﻻً ﺩﺭ ﭘﺮﺍﻧﺘﺰ ﻣﻘﺎﺑﻞ ﺩﺳﺘﻮﺭ forﺍﻧﺠﺎﻡ ﻣﻲﺷﻮﺩ ﻣﻲﺗﻮﺍﻥ ﺻﺮﻑﻧﻈﺮ ﻛﺮﺩﻩ
ﻭ ﻋﻤﻞ ﻛﺎﻫﺶ ﻳﺎ ﺍﻓﺰﺍﻳﺶ ﻣﺘﻐﻴﺮ ﺭﺍ ﺩﺭﻭﻥ ﺣﻠﻘﻪ forﺍﻧﺠﺎﻡ ﺩﺍﺩ.
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
137 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
ﻣﺜﺎﻝ:
><html
><head
><title>for</title
></head
><body
<?php
;$i=1
) ;for ( ; $i<=10
{
;">echo "$i"."<br
;$i++
}
>?
></body
></html
6-5-2ﺣﻠﻘﻪ while
ﺳﺎﺧﺘﺎﺭ ﻛﻠﻲ ﺍﻳﻦ ﺣﻠﻘﻪ ﺑﻪﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺖ:
while )ﺷﺮﻁ ﺧﺎﺗﻤﻪ(
{
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ
}
<?php
;$i = 1
) while ( $i <= 15
{
;">echo "i = "."$i is : ".($i*2)."<br
;$i=$i+1
}
>?
></body
></html
ﺷﻜﻞ 6-7
ﺩﺳﺘﻮﺭﺍﺕ ﺑﺪﻧﻪ
}
ﺷﺮﻃﻲ(while ; )ﻋﺒﺎﺭﺕ
ﻣﺜﺎﻝ:
><html
><head
><title>do...while</title
></head
><body
<?php
;$n1 = 8
do
ﭘﻴﻤﺎﻧﻪ ﻣﻬﺎﺭﺗﻰ :ﻃﺮﺍﺣﻰ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
139 ﻭﺍﺣﺪ ﻛﺎﺭﺷﺸﻢ :ﻛﺎﺭ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎ ،ﻋﻤﻠﮕﺮﻫﺎ ﻭ ﺳﺎﺧﺘﺎﺭﻫﺎﻯ ﻛﻨﺘﺮﻟﻰ
{
;">print "number: "." $n1"."<br
;$n1++
}
;) while ( $n1 > 10 && $n1 < 15
>?
></body
></html
ﺷﻜﻞ 6-8
ﺩﺭ ﻛﺪ ﻗﺒﻠﻲ ﻣﺘﻐﻴﺮ ﺍﻭﻟﻴﻪ n1ﺑﺎ ﻋﺪﺩ 8ﻣﻘﺪﺍﺭﺩﻫﻲ ﺍﻭﻟﻴﻪ ﺷــﺪﻩ ﺍﺳــﺖ ﻭ ﺩﺭ ﻋﺒﺎﺭﺕ ﺷﺮﻃﻲ
ﻣﻘﺎﺑﻞ ،whileﺑﺮﺭﺳﻲ ﺷﺪﻩ ﺍﺳﺖ ﻛﻪ ﺗﺎ ﺯﻣﺎﻧﻲ ﻛﻪ ﻣﺘﻐﻴﺮ n1ﺑﺰﺭگﺗﺮ ﺍﺯ 10ﻭ ﻛﻮﭼﻚﺗﺮ ﺍﺯ 15
ﺍﺳﺖ ﺣﻠﻘﻪ ﺍﺩﺍﻣﻪ ﻳﺎﺑﺪ ،ﺍﻣﺎ ﺩﺭ ﺷﻜﻞ 6-8ﻣﻼﺣﻈﻪ ﻣﻲﻛﻨﻴﺪ ﺑﺎ ﺍﻳﻦﻛﻪ ﺍﻳﻦ ﺷﺮﻁ ﻫﺮﮔﺰ ﺻﺤﻴﺢ
ﻧﻴﺴﺖ ،ﻳﻚﺑﺎﺭ ﺍﺟﺮﺍ ﺷﺪﻩ ﺍﺳﺖ.
6-7ﻣﺘﻐﻴﺮﻫﺎﻱ ﺳﺮﺍﺳﺮﻱ
ﺍﮔﺮ ﺩﺭ ﺑﺮﻧﺎﻣﻪ ﺑﺨﻮﺍﻫﻴﺪ ﻳﻚ ﻣﺘﻐﻴﺮ ﺭﺍ ﺑﻴﻦ ﺗﻤﺎﻡ ﻗﺴــﻤﺖﻫﺎ ﺑﻪﻃﻮﺭ ﻳﻜﺴــﺎﻥ ﺍﺳﺘﻔﺎﺩﻩ ﻛﻨﻴﺪ،
ﻣﻲﺗﻮﺍﻧﻴﺪ ﺁﻥ ﺭﺍ ﺍﺯ ﻧﻮﻉ ﺳﺮﺍﺳﺮﻱ ) (globalﺗﻌﺮﻳﻒ ﻧﻤﺎﻳﻴﺪ:
ﺷﻴﻮﻩ ﺗﻌﺮﻳﻒ ﻳﻚ ﻣﺘﻐﻴﺮ ﺳﺮﺍﺳﺮﻱ ﺑﻪ ﻓﺮﻡﻫﺎﻱ ﺯﻳﺮ ﺍﺳﺖ:
; ﻧﺎﻡ ﻣﺘﻐﻴﺮ$global
ﻭﺍژﻩﻧﺎﻣﻪ
Association ﺍﻧﺠﻤﻦ
Break ﺷﻜﺴﺘﻦ
Continue ﺍﺩﺍﻣﻪ ﺩﺍﺩﻥ
Default ﭘﻴﺶﻓﺮﺽ
Define ﻣﻘﺪﺍﺭﺩﻫﻲ
HomePage ﺻﻔﺤﻪ ﺧﺎﻧﮕﻲ
Indexed ﺩﺍﺭﺍﻯ ﺯﻳﺮﻧﻮﻳﺲ
ﺧﻼﺻﻪ ﻣﻄﺎﻟﺐ
• ﺑﺮﺍﻱ ﺍﻳﺠﺎﺩ ﻓﺎﻳﻞﻫﺎﻱ PHPﻧﻴﺎﺯﻱ ﺑﻪ ﻣﺤﻴﻂ ﻣﺨﺼﻮﺹ ﺍﻳﻦ ﺯﺑﺎﻥ ﻧﻴﺴﺖ ،ﺣﺘﻲ ﺩﺭ ﻣﺤﻴﻂ
ﻣﺘﻨﻲ ﺳﺎﺩﻩ Notepadﻧﻴﺰ ﻣﻲﺗﻮﺍﻥ ﻛﺪﻫﺎﻱ ﺁﻥ ﺭﺍ ﻧﻮﺷﺖ.
• ﻓﺎﻳﻞ HomePageﺻﻔﺤﺎﺕ ﺳﺎﻳﺖ ﺑﺎﻳﺪ ﺑﺎ ﻧﺎﻡ indexﻳﺎ defaultﺫﺧﻴﺮﻩ ﺷﻮﺩ.
• ﻣﻬﻢﺗﺮﻳﻦ ﺍﺑﺰﺍﺭ ﺗﻮﻟﻴﺪ ﺻﻔﺤﺎﺕ ﭘﻮﻳﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﻣﺘﻐﻴﺮﻫﺎﺳﺖ.
• ﻣﺘﻐﻴﺮﻫﺎﻱ PHPﻫﻤﻪ ﻣﻨﻈﻮﺭﻩ ﻫﺴــﺘﻨﺪ ﻭ ﻧﻴﺎﺯﻱ ﻧﻴﺴﺖ ﻫﻨﮕﺎﻡ ﻣﻌﺮﻓﻲ ،ﻧﻮﻉ ﻣﺘﻐﻴﺮ ﺗﻌﻴﻴﻦ
ﺷﻮﺩ.
• ﻫﻨﮕﺎﻡ ﻣﻘﺪﺍﺭﺩﻫﻲ ﻣﺘﻐﻴﺮﻫﺎﻱ ، PHPﻧﻮﻉ ﺁﻥﻫﺎ ﺑﻪﻃﻮﺭ ﺿﻤﻨﻲ ﺗﻌﻴﻴﻦ ﻣﻲﺷﻮﺩ.
• ﺁﺭﺍﻳﻪﻫﺎﻱ PHPﺩﺍﺭﺍﻱ ﺩﻭ ﻧﻮﻉ ﺍﺻﻠﻲ ﺍﻧﺪﻳﺲﺩﺍﺭ ﻭ ﺍﻧﺠﻤﻨﻲ ﻫﺴﺘﻨﺪ.
• ﺍﻧﺪﻳﺲ ﻣﻘﺎﺩﻳﺮ ﺁﺭﺍﻳﻪﻫﺎﻱ PHPﺍﺯ ﺻﻔﺮ ﺷﺮﻭﻉ ﻣﻲﺷﻮﺩ ﻳﻌﻨﻲ ﺍﻧﺪﻳﺲ ﺍﻭﻟﻴﻦ ﻋﻨﺼﺮ ﺁﺭﺍﻳﻪ
ﺻﻔﺮ ﻭ ﺍﻧﺪﻳﺲ ﺁﺧﺮﻳﻦ ﻋﻨﺼﺮ ﺁﺭﺍﻳﻪ n-1ﺍﺳﺖ.
• ﺩﺭ PHPﻣﺘﻐﻴﺮﻫﺎﻳﻲ ﻭﺟﻮﺩ ﺩﺍﺭﻧﺪ ﻛﻪ ﺑﻪﻃﻮﺭ ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﺑﺮﺍﻱ ﺍﻫﺪﺍﻑ ﺧﺎﺻﻲ
ﺩﺭ ﻧﻈﺮ ﮔﺮﻓﺘﻪ ﺷــﺪﻩﺍﻧﺪ ،ﺩﺭ ﻧﺎﻣﮕﺬﺍﺭﻱ ﻣﺘﻐﻴﺮﻫﺎ ﺑﺎﻳﺪ ﺩﻗﺖ ﻛﻨﻴﺪ ،ﻣﺘﻐﻴﺮﻱ ﻛﻪ ﺗﻌﺮﻳﻒ ﻣﻲﻛﻨﻴﺪ،
ﻫﻢﻧﺎﻡ ﺑﺎ ﻣﺘﻐﻴﺮﻫﺎﻱ ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﻧﺒﺎﺷﺪ.
• ﻋﻤﻠﮕﺮﻫﺎﻱ ﺯﺑﺎﻥ PHPﻧﻴﺰ ﻣﺎﻧﻨﺪ ﺳﺎﻳﺮ ﺯﺑﺎﻥﻫﺎ ﺑﺮﺍﻱ ﺍﻧﺠﺎﻡ ﻋﻤﻠﻴﺎﺕ ﻣﺤﺎﺳﺒﺎﺗﻲ ،ﻣﻘﺎﻳﺴﻪﺍﻱ،
ﻣﻨﻄﻘﻲ ﻭ ...ﺑﻪﻛﺎﺭ ﻣﻲﺭﻭﻧﺪ.
• ﺩﺭ ﺗﻤﺎﻡ ﺯﺑﺎﻥﻫﺎﻱ ﺑﺮﻧﺎﻣﻪﻧﻮﻳﺴــﻲ ﺍﺯ ﺟﻤﻠﻪ ، PHPﺑــﺮﺍﻱ ﻛﻨﺘﺮﻝ ﺭﻭﻧﺪ ﺍﺟﺮﺍﻱ ﺑﺮﻧﺎﻣﻪ ﺍﺯ
ﻭﺯﺍﺭﺕ ﻓﺮﻫﻨﮓ ﻭ ﺍﺭﺷﺎﺩ ﺍﺳﻼﻣﻰ
ﻧﺎﻡ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ :ﻃﺮﺍﺡ ﺻﻔﺤﺎﺕ ﻭﺏ)ﭘﻴﺸﺮﻓﺘﻪ(
ﺷﻤﺎﺭﻩ -15 / 4/ 2 :ﻑ ،ﻫـ 142
ﺁﺯﻣﻮﻥ ﻧﻈﺮﻱ
- 1ﻛﺪﻫﺎﻱ PHPﺭﺍ ﻗﺒﻞ ﺍﺯ ﺍﺟﺮﺍ ﺩﺭﻭﻥ ﻛﺪﺍﻡﻳﻚ ﺍﺯ ﻣﺤﻴﻂﻫﺎﻱ ﺯﻳﺮ ﻧﻤﻲﺗﻮﺍﻥ ﻧﻮﺷﺖ؟
ﺏNotepad - ﺍﻟﻒWord -
- 3ﻛﺪﺍﻡﻳﻚ ﺍﺯ ﺍﺳﺎﻣﻲ ﺯﻳﺮ ﻧﻤﻲﺗﻮﺍﻧﺪ ﺑﻪﻃﻮﺭ ﺧﻮﺩﻛﺎﺭ ﺑﻪ ﻋﻨﻮﺍﻥ ﺻﻔﺤﻪ ﺧﺎﻧﮕﻲ ﺗﻨﻈﻴﻢ ﺷﻮﺩ؟
ﺩindex.txt- ﺝdefault.php- ﺏindex.php - ﺍﻟﻒindex.htm -
- 8ﺩﺭ ﺁﺭﺍﻳــﻪ ) " $day = array ("first"، "Second"،"thirdﻣﺘﻐﻴــﺮ] day [1ﭼــﻪ ﻣﻘﺪﺍﺭﻱ ﺭﺍ
ﺑﺮﻣﻲﮔﺮﺩﺍﻧﺪ؟
ﺏsecond - ﺍﻟﻒfirst -
ﺁﺯﻣﻮﻥ ﻋﻤﻠﻲ