مقدمة في برمجة الويب - جامعة الإمام محمد بن سعود الإسلامية

Summary

هذه مقدمة في برمجة الويب، تغطي مفهوم الإنترنت، والعميل، والخادم، والخدمات عبر الإنترنت، والبروتوكولات المختلفة. تُركز على مكونات ملفات HTML الأساسية وكيفية بناء صفحات الويب.

Full Transcript

‫ﺍﻟﻤﻤﻠﻜﺔ ﺍﻟﻌﺮﺑﻴﺔ ﺍﻟﺴﻌﻮﺩﻳﺔ‬ ‫ﻭﺯﺍﺭﺓ ﺍﻟﺘﻌﻠﻴﻢ‬ ‫ﺟﺎﻣﻌﺔ ﺍﻹﻣﺎﻡ ﻣﺤﻤﺪ ﺑﻦ ﺳﻌﻮﺩ ﺍﻹﺳﻼﻣﻴﺔ‬ ‫ﺍﻟﻜﻠﻴﺔ ﺍﻟﺘﻄﺒﻴﻘﻴﺔ‬ ‫‪Introduction to web programming‬‬ ‫‪Advanced Web programming CS211‬‬ ‫‪Norah Alrumayh‬‬ Outlines The concept of the Int...

‫ﺍﻟﻤﻤﻠﻜﺔ ﺍﻟﻌﺮﺑﻴﺔ ﺍﻟﺴﻌﻮﺩﻳﺔ‬ ‫ﻭﺯﺍﺭﺓ ﺍﻟﺘﻌﻠﻴﻢ‬ ‫ﺟﺎﻣﻌﺔ ﺍﻹﻣﺎﻡ ﻣﺤﻤﺪ ﺑﻦ ﺳﻌﻮﺩ ﺍﻹﺳﻼﻣﻴﺔ‬ ‫ﺍﻟﻜﻠﻴﺔ ﺍﻟﺘﻄﺒﻴﻘﻴﺔ‬ ‫‪Introduction to web programming‬‬ ‫‪Advanced Web programming CS211‬‬ ‫‪Norah Alrumayh‬‬ Outlines The concept of the Internet. The difference between client and server. Internet browser. Internet services. The concept of protocol. TCP/IP protocol. How to build web pages. HTML file components. How to write an HTML program. Types of web pages. The concept of the Internet ‫ﻣﻔﻬﻮم اﻹﻧﱰﻧﺖ‬ ‫اﻹﻧﱰﻧﺖ ﻋﺒﺎرة ﻋﻦ ﺷﺒﻜﺔ ﻋﺎﳌﻴﺔ ﺗﻀﻢ ﻣﻠﻴﺎرات أﺟﻬﺰة اﻟﻜﻤﺒﻴﻮﺗﺮ وﻏ ﻫﺎ ﻣﻦ‬.‫اﻷﺟﻬﺰة اﻹﻟﻜﱰوﻧﻴﺔ‬ ‫وﻳﺴﺘﺨﺪم اﻹﻧﱰﻧﺖ ﺑﺒﺴﺎﻃﺔ ﻟﺮﺑﻂ أي ﺟﻬﺎز )ﻋﻤﻴﻞ( ﺑﺨﺎدم‬ The Internet is a global network of billions of computers and other.‫ﻣﻦ ﺧﻼل ﺷﺒﻜﺔ ﻟﻠﺤﺼﻮل ﻋﲆ اﳌﻌﻠﻮﻣﺎت‬ electronic devices. The internet simply used to connects any device (client) to a server through a network to get information. Client and Server Client is a device or software program that is used to access data or resources from another device, known as a server. Server is a computer that provides resources, data, services, or programs to other computers, known as clients. Servers are usually more powerful and have more storage than clients, as they are designed to handle large amounts of data. ‫اﻟﻌﻤﻴﻞ واﻟﺨﺎدم‬ ‫اﻟﻌﻤﻴﻞ ﻫﻮ ﺟﻬﺎز أو ﺑﺮﻧﺎﻣﺞ ﺑﺮﻣﺠﻲ ﻳﺴﺘﺨﺪم ﻟﻠﻮﺻﻮل إﱃ اﻟﺒﻴﺎﻧﺎت أو‬.‫ ﻳُﻌﺮف ﺑﺎﺳﻢ اﻟﺨﺎدم‬،‫اﳌﻮارد ﻣﻦ ﺟﻬﺎز آﺧﺮ‬ ‫اﻟﺨﺎدم ﻫﻮ ﺟﻬﺎز ﻛﻤﺒﻴﻮﺗﺮ ﻳﻮﻓﺮ اﳌﻮارد أو اﻟﺒﻴﺎﻧﺎت أو اﻟﺨﺪﻣﺎت أو‬.‫ ﺗ ُﻌﺮف ﺑﺎﺳﻢ اﻟﻌﻤﻼء‬،‫اﻟﱪاﻣﺞ ﻷﺟﻬﺰة ﻛﻤﺒﻴﻮﺗﺮ أﺧﺮى‬ ،‫ﻋﺎد ًة ﻣﺎ ﺗﻜﻮن اﻟﺨﻮادم أﻛ ﻗﻮة وﻟﺪﻳﻬﺎ ﻣﺴﺎﺣﺔ ﺗﺨﺰﻳﻦ أﻛﱪ ﻣﻦ اﻟﻌﻤﻼء‬.‫ﻷﻧﻬﺎ ﻣﺼﻤﻤﺔ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﻛﻤﻴﺎت ﻛﺒ ة ﻣﻦ اﻟﺒﻴﺎﻧﺎت‬ Client VS Server ‫اﻟﻌﻤﻴﻞ‬ ‫ﺟﻬﺎز ﻛﻤﺒﻴﻮﺗﺮ ﻳﺘﺼﻞ ﺑﺨﺎدم ﻣﻦ أﺟﻞ‬ client server ‫اﻟﺨﺎدم‬ a computer that connects to a server in order a computer that provides those resources or.‫اﻟﻮﺻﻮل إﱃ اﳌﻮارد أو اﻟﺨﺪﻣﺎت‬ ‫ﺟﻬﺎز ﻛﻤﺒﻴﻮﺗﺮ ﻳﻮﻓﺮ ﺗﻠﻚ اﳌﻮارد أو‬ ‫ﻳﺒﺪأ اﻻﺗﺼﺎل ﻣﻦ أﺟﻞ ﻃﻠﺐ‬ to access resources or services. services..‫اﻟﺨﺪﻣﺎت‬ ‫اﳌﻌﻠﻮﻣﺎت‬ ‫ﻳﺴﺘﺠﻴﺐ ﻟﻄﻠﺒﺎت اﻟﻌﻤﻼء‬ ‫اﳌﻮﺟﻮدة ﻋﲆ أﺟﻬﺰة ﻛﻤﺒﻴﻮﺗﺮ اﳌﺴﺘﺨﺪم‬.‫اﳌﻮﺟﻮدﻳﻦ ﻋﲆ اﻟﺸﺒﻜﺔ‬ Initiates communication in order to request Responds to requests from clients information located on user computers located on network ‫ﺗﺴﻤﺢ ﻟﻨﺎ ﺷﺒﻜﺔ اﻹﻧﱰﻧﺖ ﺑﺎﻟﻮﺻﻮل إﱃ ﻛﻤﻴﺎت ﻫﺎﺋﻠﺔ ﻣﻦ اﳌﻌﻠﻮﻣﺎت ﻣﺜﻞ‬ ‫ و ﻜﻦ ﺗﺼﻨﻴﻒ اﻟﺨﺪﻣﺎت‬.‫اﻟﻨﺼﻮص واﻟﺮﺳﻮﻣﺎت واﻟﺼﻮت واﻟﱪاﻣﺞ‬ :‫إﱃ أرﺑﻊ ﻓﺌﺎت ﻣﺨﺘﻠﻔﺔ‬ Internet services ‫ﺧﺪﻣﺎت اﻻﺗﺼﺎﻻت اﻟﺘﻲ ﺗﻮﻓﺮ ﺗﺒﺎدل اﳌﻌﻠﻮﻣﺎت ﻣﻊ اﻷﻓﺮاد أو‬ ‫ ﻣﺜﻞ رﺳﺎﺋﻞ اﻟﱪﻳﺪ‬.‫اﳌﺠﻤﻮﻋﺎت‬.‫ﺗﺴﻤﺢ ﺧﺪﻣﺎت اﻟﻮﻳﺐ ﺑﺘﺒﺎدل اﳌﻌﻠﻮﻣﺎت ﺑ اﻟﺘﻄﺒﻴﻘﺎت ﻋﲆ اﻟﻮﻳﺐ‬ Archie‫ﺧﺪﻣﺎت اﺳﱰﺟﺎع اﳌﻌﻠﻮﻣﺎت اﻟﺘﻲ ﺗﻮﻓﺮ ﺳﻬﻮﻟﺔ اﻟﻮﺻﻮل إﱃ اﳌﻌﻠﻮﻣﺎت اﳌﻮﺟﻮدة ﻋﲆ‬ ،‫ ﻣﺜﻞ ﻧﻘﻞ اﳌﻠﻔﺎت‬.‫اﻹﻧﱰﻧﺖ‬ ‫ﺷﺒﻜﺔ اﻟﻮﻳﺐ اﻟﻌﺎﳌﻴﺔ ﺗﻮﻓﺮ ﻃﺮﻳﻘﺔ ﻟﻠﻮﺻﻮل إﱃ اﳌﺴﺘﻨﺪات اﳌﻨﺘﴩة ﻋﱪ اﻟﻌﺪﻳﺪ ﻣﻦ‬.‫ ﻗﺪ ﺗﺤﺘﻮي ﻫﺬه اﳌﺴﺘﻨﺪات ﻋﲆ ﻧﺼﻮص ورﺳﻮﻣﺎت وﺻﻮت وﻓﻴﺪﻳﻮ وارﺗﺒﺎﻃﺎت ﺗﺸﻌﺒﻴﺔ‬.‫اﻟﺨﻮادم ﻋﱪ اﻹﻧﱰﻧﺖ‬ The internet allows us to access huge amounts of information such as text, graphics, sound, and software. The services can be categorized into four different categories : Communication Services that offer exchange of information with individuals or groups. such as Mails Information Retrieval Services offering easy access to information present on the internet. such as File Transfer, Archie Web Services allow exchange of information between applications on the web. World Wide Web It offers a way to access documents spread over the several servers over the internet. These documents may contain texts, graphics, audio, video, hyperlinks. ‫اﻹﻧﱰﻧﺖ ﻋﺒﺎرة ﻋﻦ ﺷﺒﻜﺔ ﻣﻌﻘﺪة ﻣﻦ اﻟﺸﺒﻜﺎت اﳌﱰاﺑﻄﺔ‬. ‫اﻟﺘﻲ ﺗﺤﻜﻤﻬﺎ ﺑﺮوﺗﻮﻛﻮﻻت وﻣﻌﺎﻳ‬ ‫اﻟﱪوﺗﻮﻛﻮل ﻋﺒﺎرة ﻋﻦ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻘﻮاﻋﺪ اﻟﺘﻲ ﺗﺤﻜﻢ ﻛﻴﻔﻴﺔ ﻧﻘﻞ اﻟﺒﻴﺎﻧﺎت‬ The concept of protocol.‫ﻋﱪ اﻟﺸﺒﻜﺎت‬..UDP‫ و‬TCP.‫ﻓﺮﻳﺪ ﻟﻜﻞ ﺟﻬﺎز ﻣﺘﺼﻞ ﺑﺎﻹﻧﱰﻧﺖ واﻟﺬي ﻳﻌﻤﻞ ﻛﻤﻌﺮف اﻓﱰاﴈ ﻟﻪ‬ ‫ﺑﺮوﺗﻮﻛﻮﻻت اﻟﻨﻘﻞ اﻷﻛ ﺷﻴﻮ ًﻋﺎ ﻫﻲ‬IP ‫ ﻳﺘﻢ ﺗﻌﻴ ﻋﻨﻮان‬.)‫ﺑﺮوﺗﻮﻛﻮل اﻹﻧﱰﻧﺖ‬IP ( ‫ﻳﻌﺘﻤﺪ أﺳﺎس اﻹﻧﱰﻧﺖ ﻋﲆ ﺑﺮوﺗﻮﻛﻮل ﻳﺴﻤﻰ‬ The Internet is a complex network of interconnected networks governed by protocols and standards. A protocol is a set of rules that govern how data is transmitted across networks. The foundation of the Internet is built on a protocol called IP (Internet Protocol). Every device connected to the internet is assigned a unique IP address which serves as its virtual identifier. The most common transport protocols are TCP and UDP. ‫ ﺳﻴﺘﻢ إرﺳﺎل اﻟﺤﺰم اﳌﻔﻘﻮدة ﻣﺮة أﺧﺮى إذا ﻳﺘﻢ‬.‫ ﺳﻴﻘﺮ اﳌﺴﺘﻠﻢ ﺑﺎﺳﺘﻼم ﻛﻞ ﺣﺰﻣﺔ ﺗﺼﻞ‬،.‫إﻗﺮار اﻻﺳﺘﻼم‬ TCP/IP protocol. ‫ ﺗﺼﻔﺢ اﻟﻮﻳﺐ‬، ‫ اﻟﱪﻳﺪ اﻹﻟﻜﱰو‬:‫اﻟﺘﻄﺒﻴﻖ اﻟﻨﻤﻮذﺟﻲ‬TCP.‫ﺟﻤﻴﻊ اﻟﺤﺰم ﺑﺎﻟﱰﺗﻴﺐ ﺠﺮد ﺑﺪء اﻹرﺳﺎل‬ ‫وﺻﻮل‬ ‫ﻋﱪ‬TCP.‫اﺗﺼﺎﻻً ﻣﻊ اﳌﺴﺘﻠﻢ‬ ‫ﻳﻀﻤﻦ‬TCP. ‫ ﻳﻔﺘﺢ‬،‫ﻗﺒﻞ إرﺳﺎل اﻟﺒﻴﺎﻧﺎت‬TCP/IP ‫ﰲ ﺟﺰء اﻟﺒﻴﺎﻧﺎت ﻟﻜﻞ ﺣﺰﻣﺔ ﺗﺴﺘﺨﺪم‬TCP،‫( ﻫﻮ ﺑﺮوﺗﻮﻛﻮل ﻧﻘﻞ‬ The Transmission Control Protocol (TCP) is a transport protocol, meaning it dictates the way data is sent and received. A TCP header is included in the data portion of each packet that uses TCP/IP. Before transmitting data, TCP opens a connection with the recipient. TCP ensures that all packets arrive in order once transmission begins. Via TCP, the recipient will acknowledge receiving each packet that arrives. Missing packets will be sent again if receipt is not acknowledged. Typical application : email, web browsing UDP/IP protocol. The User Datagram Protocol, or UDP, is another widely used transport protocol. It is faster than TCP, but it is also less reliable. UDP does not make sure all packets are delivered and in order, and it does not establish a connection before beginning or receiving transmissions. Typical application : VOIP, Music streaming.‫ ﺑﺚ اﳌﻮﺳﻴﻘﻰ‬،VOIP.‫ وﻻ ﻳﻨﺸﺊ اﺗﺼﺎﻻً ﻗﺒﻞ ﺑﺪء أو ﺗﻠﻘﻲ ﻋﻤﻠﻴﺎت اﻹرﺳﺎل‬،‫ﻣﻦ ﺗﺴﻠﻴﻢ ﺟﻤﻴﻊ اﻟﺤﺰم وﺗﺮﺗﻴﺒﻬﺎ‬ :‫اﻟﺘﻄﺒﻴﻖ اﻟﻨﻤﻮذﺟﻲ‬UDP.‫ وﻟﻜﻨﻪ أﻗﻞ ﻣﻮﺛﻮﻗﻴﺔ أﻳﻀً ﺎ‬، ‫ﻻ ﻳﺘﺄﻛﺪ ﺑﺮوﺗﻮﻛﻮل‬TCP ‫ إﻧﻪ أﴎع ﻣﻦ‬.‫ ﻫﻮ ﺑﺮوﺗﻮﻛﻮل ﻧﻘﻞ آﺧﺮ ﻣﺴﺘﺨﺪم ﻋﲆ ﻧﻄﺎق واﺳﻊ‬،UDP ‫ أو‬،‫ﺑﺮوﺗﻮﻛﻮل ﺑﻴﺎﻧﺎت اﳌﺴﺘﺨﺪم‬ Internet browser )Microso Edge‫ و‬Google Chrome‫ﻣﺘﺼﻔﺢ اﻹﻧﱰﻧﺖ ﻫﻮ ﺗﻄﺒﻴﻖ ﺑﺮﻣﺠﻲ ﻻﺳﱰداد وﻋﺮض‬ ‫ﻣﺼﺎدر اﳌﻌﻠﻮﻣﺎت ﻋﲆ اﻹﻧﱰﻧﺖ‬ ‫وأﺷﻬﺮ ﻣﺘﺼﻔﺤﺎت اﻟﻮﻳﺐ ﻫﻲ‬Internet Explorer ‫ﺳﺎﺑﻘًﺎ( و‬Mozilla Firefox ‫و‬Apple Safari. Internet browser is a software application for retrieving, presenting, and traversing information resources on the internet The most popular web browsers are Google Chrome, Microsoft Edge (formerly Internet Explorer), Mozilla Firefox, and Apple’s Safari. Why Internet browser..‫ ﻟﻠﺘﻮاﺻﻞ ﻣﻊ ﺧﻮادم اﻟﻮﻳﺐ ﻋﱪ اﻹﻧﱰﻧﺖ‬HTTP.‫اﻟﻄﺮﻳﻘﺔ اﻟﺸﺎﺋﻌﺔ ﻟﻠﻮﺻﻮل إﱃ اﳌﻮﻗﻊ اﻹﻟﻜﱰو ﻫﻲ اﺳﺘﺨﺪام ﻣﺘﺼﻔﺢ اﻹﻧﱰﻧﺖ‬ (‫ﻳﺴﺘﺨﺪم ﻣﺘﺼﻔﺢ اﻹﻧﱰﻧﺖ ﺑﺮوﺗﻮﻛﻮل ﻃﺒﻘﺔ اﻟﺘﻄﺒﻴﻖ )ﺑﺮوﺗﻮﻛﻮل ﻧﻘﻞ اﻟﻨﺺ اﻟﺘﺸﻌﺒﻲ‬ The common way to access the website is using the internet browser. Internet browser use an application layer protocol (Hypertext Transfer Protocol) HTTP to communicate with web servers via the internet..‫اﳌﻮﻗﻊ اﻹﻟﻜﱰو ﻫﻮ ﻋﺒﺎرة ﻋﻦ ﻣﺠﻤﻮﻋﺔ ﻣﻦ ﺻﻔﺤﺎت اﻟﻮﻳﺐ اﳌﺴﺘﻀﺎﻓﺔ ﻋﲆ ﺧﺎدم اﻟﻮﻳﺐ‬ Website ‫اﳌﻮﻗﻊ اﻹﻟﻜﱰو ﻫﻮ ﻣﻜﺎن ﻋﲆ اﻹﻧﱰﻧﺖ ﺣﻴﺚ ﻜﻨﻚ اﻻﺣﺘﻔﺎظ ﺑﺎﳌﻌﻠﻮﻣﺎت‬.‫ﻟﻴﺘﻤﻜﻦ اﻵﺧﺮون ﻣﻦ رؤﻳﺘﻬﺎ‬ ‫ﻳﺘﻢ ﺗﺤﺪﻳﺪ ﺟﻤﻴﻊ ﻣﻮاﻗﻊ اﻟﻮﻳﺐ ﻣﻦ ﺧﻼل ﻋﻨﻮان ﻓﺮﻳﺪ ﻳﺨﱪ اﳌﺘﺼﻔﺤﺎت‬..‫ﻜﺎن وﺟﻮدﻫﺎ‬ A website is a collocation of web pages hosted on web server. A website is a place on the internet where you can keep information for others to see. All websites are identified by a unique address, which tells browsers where they are located. How to build web pages Web pages can be build by HyperText Markup Language (HTML),.JavaScript‫ و‬،(CSS) ‫ وأوراق اﻷ ﺎط اﳌﺘﺘﺎﻟﻴﺔ‬،(HTML) ‫ﻜﻦ إﻧﺸﺎء ﺻﻔﺤﺎت اﻟﻮﻳﺐ ﺑﺎﺳﺘﺨﺪام ﻟﻐﺔ ﺗﺮﻣﻴﺰ اﻟﻨﺺ اﻟﺘﺸﻌﺒﻲ‬ Cascading Style Sheets (CSS), and JavaScript. HTML provides the basic CSS is used to control JavaScript is used to structure of sites, which is presentation, formatting, control the behavior enhanced and modified by and layout of web pages. of web pages. CSS and JavaScript. ‫ﻟﻠﺘﺤﻜﻢ ﰲ‬ ‫اﻟﻌﺮض واﻟﺘﻨﺴﻴﻖ‬..JavaScript‫ و‬CSS ‫ واﻟﺘﻲ ﻳﺘﻢ ﺗﺤﺴﻴﻨﻬﺎ وﺗﻌﺪﻳﻠﻬﺎ ﺑﻮاﺳﻄﺔ‬،‫ اﻟﺒﻨﻴﺔ اﻷﺳﺎﺳﻴﺔ ﻟﻠﻤﻮاﻗﻊ‬HTML ‫ﻳﻮﻓﺮ‬..‫وﺗﺨﻄﻴﻂ ﺻﻔﺤﺎت اﻟﻮﻳﺐ‬CSS ‫اﺳﺘﺨﺪام‬.‫ ﻟﻠﺘﺤﻜﻢ ﰲ ﺳﻠﻮك ﺻﻔﺤﺎت اﻟﻮﻳﺐ‬JavaScript ‫ﻳﺘﻢ اﺳﺘﺨﺪام‬ ‫ﻳﺘﻢ‬ Types of web pages Two types of web page Static web page , the content remains the same whenever users access it. Dynamic web page, the content based on a central database to store the information. ‫ﻧﻮﻋﺎن ﻣﻦ ﺻﻔﺤﺎت اﻟﻮﻳﺐ‬.‫ ﺣﻴﺚ ﻳﻈﻞ اﳌﺤﺘﻮى ﻛ ﻫﻮ ﻛﻠ ﻗﺎم اﳌﺴﺘﺨﺪﻣﻮن ﺑﺎﻟﻮﺻﻮل إﻟﻴﻬﺎ‬،‫ﺻﻔﺤﺔ وﻳﺐ ﺛﺎﺑﺘﺔ‬ ‫ ﺣﻴﺚ ﻳﻌﺘﻤﺪ اﳌﺤﺘﻮى ﻋﲆ ﻗﺎﻋﺪة ﺑﻴﺎﻧﺎت ﻣﺮﻛﺰﻳﺔ ﻟﺘﺨﺰﻳﻦ‬،‫ﺻﻔﺤﺔ وﻳﺐ دﻳﻨﺎﻣﻴﻜﻴﺔ‬.‫اﳌﻌﻠﻮﻣﺎت‬ : ‫ ﻳﺤﺪد ﻧﻮع اﳌﺴﺘﻨﺪ أو ﻳﻮﺟﻪ اﳌﺘﺼﻔﺢ ﺣﻮل إﺻﺪار‬HTML. : ‫ ﻳﺨﱪ ﻫﺬا اﻟﻮﺳﻢ اﳌﺘﺼﻔﺢ ﺑﺄﻧﻪ ﻣﺴﺘﻨﺪ‬HTML. ‫ ﻳﺼﻒ اﻟﻨﺺ اﳌﻮﺟﻮد ﺑ وﺳﻢ‬html ‫ﻣﺴﺘﻨﺪ اﻟﻮﻳﺐ‬. : ‫ ﻳﺠﺐ إﻏﻼﻗﻪ ﻗﺒﻞ ﻓﺘﺢ وﺳﻢ‬.(‫ﻳﺤﺘﻮي ﻋﲆ اﻟﺒﻴﺎﻧﺎت اﻟﻮﺻﻔﻴﺔ )ﻣﻌﻠﻮﻣﺎت ﺣﻮل اﳌﺴﺘﻨﺪ‬ HTML file components. body. : ‫ ﻳﺴﺘﺨﺪم ﻹﺿﺎﻓﺔ ﻋﻨﻮان ﻟﺼﻔﺤﺔ‬HTML ‫اﻟﺘﻲ ﺗﻈﻬﺮ ﰲ أﻋﲆ ﻧﺎﻓﺬة اﳌﺘﺼﻔﺢ‬. )‫: ‫ ﻳﺤﺘﻮي ﻫﺬا اﻟﻮﺳﻢ ﻋﲆ اﳌﺤﺘﻮى اﻟﺮﺋﻴﴘ ﳌﺴﺘﻨﺪ‬HTML. : ‫< ﻳﺼﻒ اﻟﻨﺺ اﳌﻮﺟﻮد ﺑ وﺳﻢ‬h1> ‫ﻋﻨﻮان اﳌﺴﺘﻮى اﻷول ﻟﺼﻔﺤﺔ اﻟﻮﻳﺐ‬. : ‫< ﻳﺼﻒ اﻟﻨﺺ اﳌﻮﺟﻮد ﺑ وﺳﻢ‬p> ‫ﻓﻘﺮة ﺻﻔﺤﺔ اﻟﻮﻳﺐ‬.. : It defines the document type or it instruct the browser about the version of HTML. :This tag informs the browser that it is an HTML document. Text between html tag describes the web document. :it contains the metadata(information about the document). It must be closed before the body tag opens. : it is used to add title of that HTML page which appears at the top of the browser window. (Optional) :This tag contains the main content of the HTML document. : Text between tag describes the first level heading of the webpage. : Text between tag describes the paragraph of the webpage. How to write an HTML program Using Text editor, such as Windows Notepad...‫اﻓﺘﺢ اﳌﻠﻒ ﰲ ﻣﺘﺼﻔﺢ اﻹﻧﱰﻧﺖ ﳌﺸﺎﻫﺪة اﻟﻨﺘﻴﺠﺔ‬HTML Create a file with.html extension ‫ﻛﺘﺎﺑﺔ ﻛﻮد‬html.. ‫إﻧﺸﺎء ﻣﻠﻒ ﺑﺎﻣﺘﺪاد‬Windows Notepad ‫ ﻣﺜﻞ‬،‫اﺳﺘﺨﺪام ﻣﺤﺮر اﻟﻨﺼﻮص‬ Write an HTML code Open the file in Internet browser to see the result. HTML example The End ‫ﺍﻟﻤﻤﻠﻜﺔ ﺍﻟﻌﺮﺑﻴﺔ ﺍﻟﺴﻌﻮﺩﻳﺔ‬ ‫ﻭﺯﺍﺭﺓ ﺍﻟﺘﻌﻠﻴﻢ‬ ‫ﺟﺎﻣﻌﺔ ﺍﻹﻣﺎﻡ ﻣﺤﻤﺪ ﺑﻦ ﺳﻌﻮﺩ ﺍﻹﺳﻼﻣﻴﺔ‬ ‫ﺍﻟﻜﻠﻴﺔ ﺍﻟﺘﻄﺒﻴﻘﻴﺔ‬ ‫‪Introduction to PHP‬‬ ‫‪Advanced Web programming CS211‬‬ ‫‪Bashair AL-Jarba‬‬ ‫‪Norah Alrumayh‬‬ Outlines The concept of PHP. What Can PHP Do? Why PHP? What is a PHP File? Basic PHP Syntax. Components of the PHP language: o Comments. o Variables. o PHP keywords. o Constants. o Operations:  Attributive operations.  Calculations operations.  Relational operations.  Boolean operations. o Print codes (echo-print-printf-sprintf). o Structural control tools:  Condition tools (if-if else-elseif-switch).  Rotation tools (for-while-do while).  Turning tools (break-continue)...‫وﻫﻲ ﻟﻐﺔ ﺑﺮﻣﺠﺔ ﻧﺼﻴﺔ ﻣﻦ ﺟﺎﻧﺐ اﻟﺨﺎدم‬ PHP: Hypertext Preprocessor ‫اﺧﺘﺼﺎر ﻟـ‬ The concept of PHP.‫ﺗ ُﺴﺘﺨﺪم ﻹﻧﺸﺎء ﺻﻔﺤﺎت وﻳﺐ دﻳﻨﺎﻣﻴﻜﻴﺔ وﺗﻔﺎﻋﻠﻴﺔ‬ Example:   Acronym for PHP: Hypertext Preprocessor.       It is used to make a dynamic and interactive web pages. Output: It is open-source (free). Hello! I am using PHP!.XML‫ و‬XHTML ‫ ﻣﺜﻞ‬،‫ ﻜﻨﻚ أﻳﻀً ﺎ إﺧﺮاج أي ﻧﺺ‬.PDF‫ ﻜﻨﻚ إﺧﺮاج اﻟﺼﻮر‬. ‫أو ﻣﻠﻔﺎت‬HTML ‫ ﻻ ﺗﻘﺘﴫ ﻋﲆ إﺧﺮاج‬،PHP.‫ﺗﺸﻔ اﻟﺒﻴﺎﻧﺎت‬ ‫ﻣﻊ‬PHP.‫ﻟﻠﺘﺤﻜﻢ ﰲ وﺻﻮل اﳌﺴﺘﺨﺪم‬ What Can PHP Do? ‫ ﻜﻦ ﻟـ‬PHP.‫إﺿﺎﻓﺔ ﺑﻴﺎﻧﺎت إﱃ ﻗﺎﻋﺪة اﻟﺒﻴﺎﻧﺎت وﺣﺬﻓﻬﺎ وﺗﻌﺪﻳﻠﻬﺎ‬ ‫ ﻜﻦ اﺳﺘﺨﺪام‬PHP.‫إرﺳﺎل ﻣﻠﻔﺎت ﺗﻌﺮﻳﻒ اﻻرﺗﺒﺎط واﺳﺘﻼﻣﻬﺎ‬ ‫ ﻜﻦ ﻟـ‬PHP.‫ﺟﻤﻊ ﺑﻴﺎﻧﺎت اﻟﻨ ذج‬ ‫ ﻜﻦ ﻟـ‬PHP.‫إﻧﺸﺎء ﻣﻠﻔﺎت ﻋﲆ اﻟﺨﺎدم وﻓﺘﺤﻬﺎ وﻗﺮاءﺗﻬﺎ وﻛﺘﺎﺑﺘﻬﺎ وﺣﺬﻓﻬﺎ وإﻏﻼﻗﻬﺎ‬ ‫ ﻜﻦ ﻟـ‬PHP. ‫إﻧﺸﺎء ﻣﺤﺘﻮى ﺻﻔﺤﺔ دﻳﻨﺎﻣﻴ‬ ‫ ﻜﻦ ﻟـ‬PHP ‫ﻜﻦ ﻟـ‬ PHP can generate dynamic page content. PHP can create, open, read, write, delete, and close files on the server. PHP can collect form data. PHP can send and receive cookies. PHP can add, delete, modify data in your database. PHP can be used to control user-access. PHP can encrypt data. With PHP you are not limited to output HTML. You can output images or PDF files. You can also output any text, such as XHTML and XML..‫ وﻳﻌﻤﻞ ﺑﻜﻔﺎءة ﻋﲆ ﺟﺎﻧﺐ اﻟﺨﺎدم‬PHP.‫ﻣﺠﺎﻧﻴًﺎ‬ Why PHP? ‫ﻣﻦ اﻟﺴﻬﻞ ﺗﻌﻠﻢ‬PHP.‫ﻣﺠﻤﻮﻋﺔ واﺳﻌﺔ ﻣﻦ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬ ‫ﻳﻌﺪ‬PHP.(‫ إﻟﺦ‬، ‫ﻳﺪﻋﻢ‬IIS‫ و‬Apache) ‫ ﻣﻊ ﺟﻤﻴﻊ اﻟﺨﻮادم اﳌﺴﺘﺨﺪﻣﺔ اﻟﻴﻮم ﺗﻘﺮﻳﺒًﺎ‬PHP.(‫ إﻟﺦ‬، ‫ﻳﺘﻮاﻓﻖ‬Mac OS X‫ و‬Unix‫ و‬Linux‫ و‬Windows) ‫ ﻋﲆ ﻣﻨﺼﺎت ﻣﺨﺘﻠﻔﺔ‬PHP ‫ﻳﻌﻤﻞ‬ PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.). PHP is compatible with almost all servers used today (Apache, IIS, etc.). PHP supports a wide range of databases. PHP is free. PHP is easy to learn and runs efficiently on the server side. What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code. PHP code is executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php" php." ‫ ﻟﻬﺎ اﻣﺘﺪاد‬PHP‫ﻋﺎدﻳﺔ‬ ‫ﻣﻠﻔﺎت‬HTML‫ وﻳﺘﻢ إرﺟﺎع اﻟﻨﺘﻴﺠﺔ إﱃ‬،‫ﻋﲆ اﻟﺨﺎدم‬ ‫اﳌﺘﺼﻔﺢ ﺑﺼﻴﻐﺔ‬PHP. ‫ﻳﺘﻢ ﺗﻨﻔﻴﺬ ﻛﻮد‬PHP ‫ وﻛﻮد‬JavaScript‫ و‬CSS‫ و‬HTML‫ ﻋﲆ ﻧﺺ و‬PHP ‫ﻜﻦ أن ﺗﺤﺘﻮي ﻣﻠﻔﺎت‬ :‫ﺑـ‬ PHP.‫ﰲ أي ﻣﻜﺎن ﰲ اﳌﺴﺘﻨﺪ‬ Basic PHP Syntax ‫ﻳﺒﺪأ ﻧﺺ‬PHP. ‫ ﻜﻦ وﺿﻊ ﻧﺺ‬PHP ‫ وﺑﻌﺾ أﻛﻮاد اﻟﱪﻣﺠﺔ اﻟﻨﺼﻴﺔ‬HTML ‫ﻋﺎد ًة ﻋﲆ ﻋﻼﻣﺎت‬ PHP ‫?      Comments.‫ ﺳﻄﺮ واﺣﺪ وﻣﺘﻌﺪد اﻷﺳﻄﺮ‬: ‫ﻫﻨﺎك‬PHP.‫ﻳﺘﻢ اﺳﺘﺨﺪاﻣﻪ ﻹﻋﻼم اﻷﺷﺨﺎص ﺎ ﻓﻌﻠﺘﻪ ﰲ اﻟﻜﻮد‬.‫ﻻ ﻳﺘﻢ ﺗﻨﻔﻴﺬه ﰲ اﻟﱪﻧﺎﻣﺞ‬ ‫ﻫﻨﺎك ﻧﻮﻋﺎن ﻣﻦ ﺑﻨﺎء اﻟﺠﻤﻠﺔ ﻟﺘﻌﻠﻴﻘﺎت‬ It is used to inform the people what did you do in the code. It is not executed in the program. are two types of syntax for PHP comments : single-line and multiple-line. There Example (Single-line Comments): Example (Multiple-line Comments):            */  ?>    .‫ﺗ ُﺴﺘﺨﺪم اﳌﺘﻐ ات ﻟﺘﺨﺰﻳﻦ اﻟﺒﻴﺎﻧﺎت‬ PHP ‫ وﻻ ﻳﺘﻌ ﻋﻠﻴﻬﺎ ﺗﺤﺪﻳﺪ ﻧﻮع اﻟﺒﻴﺎﻧﺎت اﻟﺬي ﻳﻨﺘﻤﻲ إﻟﻴﻪ‬،‫ﻫﻲ ﻟﻐﺔ ذات ﻧﻮع ﻓﻀﻔﺎض‬.(‫ ﻣﺨﺘﻠﻔﺎن‬Name$‫ و‬name.(_‫و‬ Variables $) ‫أﺳ ء اﳌﺘﻐ ات ﺣﺴﺎﺳﺔ ﻟﺤﺎﻟﺔ اﻷﺣﺮف‬9-0‫ و‬A-z:. ‫ ﻣﺘﺒﻮﻋﺔ ﺑﺎﺳﻢ اﳌﺘﻐ‬$ ‫ﻳﺒﺪأ اﺳﻢ اﳌﺘﻐ ﺑﻌﻼﻣﺔ‬.‫ﻳﺠﺐ أن ﻳﺒﺪأ اﺳﻢ اﳌﺘﻐ ﺑﺤﺮف أو ﺣﺮف ﴍﻃﺔ ﺳﻔﻠﻴﺔ‬.‫ﻻ ﻜﻦ أن ﻳﺒﺪأ اﺳﻢ اﳌﺘﻐ ﺑﺮﻗﻢ‬ ) ‫ﻻ ﻜﻦ أن ﻳﺤﺘﻮي اﺳﻢ اﳌﺘﻐ إﻻ ﻋﲆ أﺣﺮف أﺑﺠﺪﻳﺔ رﻗﻤﻴﺔ وﻋﻼﻣﺎت ﴍﻃﺔ ﺳﻔﻠﻴﺔ‬PHP. ‫اﳌﺘﻐ‬ Variables are used to store data. ‫ﺗﻮﺟﺪ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻘﻮاﻋﺪ ﻹﻋﻼن اﳌﺘﻐ ات ﰲ‬ Syntax of declaring a variable PHP is a Loosely Typed Language, did not have to tell which data type the $variablename = value; variable is. There are set of RULES to declare variables in PHP: Example:   The name of variable starts with $ sign followed by the name of the variable.    underscores (A-z, 0-9, and _ ). Output:  The names of variable are case- sensitive ($name and $Name are different). I am using PHP variable ‫ﻋﲆ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻜﻠ ت اﻷﺳﺎﺳﻴﺔ اﻟﺘﻲ ﺗﻌﺪ ﻛﻠ ت ﻣﺤﺠﻮزة‬ PHP keywords.‫وﻻ ﻜﻦ اﺳﺘﺨﺪاﻣﻬﺎ ﻛﺄﺳ ء وﻇﺎﺋﻒ أو أﺳ ء ﻓﺌﺎت أو أﺳ ء ﻃﺮق‬ PHP ‫ﺗﺤﺘﻮي ﻟﻐﺔ‬ ، ‫ واﻟﻮﻇﺎﺋﻒ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ اﳌﺴﺘﺨﺪم‬،‫ واﻟﻮﻇﺎﺋﻒ‬،‫واﻟﻔﺌﺎت‬..‫)ﻟﻴﺴﺖ ﺣﺴﺎﺳﺔ ﻟﺤﺎﻟﺔ اﻷﺣﺮف‬.‫ إﻟﺦ‬،if، else، while، echo ‫اﻷﺳﺎﺳﻴﺔ (ﻋﲆ ﺳﺒﻴﻞ اﳌﺜﺎل‬ ‫ اﻟﻜﻠ ت‬،PHP ‫ﰲ‬ PHP has a set of keywords that are reserved words Example: which cannot be used as function names, class not case-sensitive. Output: Hello World! Hello World! Hello World! Constants Example(case-sensitive): It is an identifier for a simple value. Output: Syntax:.() :‫اﻟﺒﻨﻴﺔ اﻟﻨﺤﻮﻳﺔ‬ define.‫إﻧﻪ ﻣﻌﺮف ﻟﻘﻴﻤﺔ ﺑﺴﻴﻄﺔ‬ Welcome to PHP define(name, value, case-insensitive).‫ﻻ ﻜﻦ ﺗﻐﻴ ه أﺛﻨﺎء ﺗﻨﻔﻴﺬ اﻟﱪﻧﺎﻣﺞ اﻟﻨﴢ‬ ‫ اﺳﺘﺨﺪم اﻟﺪاﻟﺔ‬،‫ﻟﺘﻌﺮﻳﻒ ﺛﺎﺑﺖ‬define(name, value, case-insensitive) Example(case-insensitive): name: ‫ﻳﺤﺪد اﺳﻢ اﻟﺜﺎﺑﺖ‬ Default is false. Output: Welcome to PHP Constants.const ‫ وذﻟﻚ ﺑﺎﺳﺘﺨﺪام اﻟﻜﻠﻤﺔ اﻷﺳﺎﺳﻴﺔ‬،‫ﻫﻨﺎك ﻃﺮﻳﻘﺔ أﺧﺮى ﻟﺘﺤﺪﻳﺪ اﻟﺜﻮاﺑﺖ‬ There are another way to define a constants, by using const keyword. Example: Output: Welcome to PHP Constants define() function vs. const keyword const keyword define() function Always case-sensitive Has a case-insensitive option. Cannot be defined inside another block Can be defined inside another block scope, like inside a function or inside an scope. if statement. ‫ﺣﺴﺎﺳﺔ دا ًﺎ ﻟﺤﺎﻟﺔ اﻷﺣﺮف‬ () ‫ ﻣﺜﻞ داﺧﻞ داﻟﺔ أو داﺧﻞ ﻋﺒﺎرة‬،‫ﻻ ﻜﻦ ﺗﻌﺮﻳﻔﻬﺎ داﺧﻞ ﻧﻄﺎق ﻛﺘﻠﺔ آﺧﺮ‬ ‫ﺗﺤﺘﻮي ﻋﲆ ﺧﻴﺎر ﻻ ﻴﺰ ﺑ اﻷﺣﺮف اﻟﻜﺒ ة واﻟﺼﻐ ة‬ const ‫ﻛﻠﻤﺔ أﺳﺎﺳﻴﺔ‬if....‫ ﻜﻦ ﺗﻌﺮﻳﻔﻬﺎ داﺧﻞ ﻧﻄﺎق ﻛﺘﻠﺔ أﺧﺮى‬define ‫داﻟﺔ‬ Operations Operators are used to perform operations on variables and values. There are many types of PHP operations like:  Attributive operations.  Calculations operations. :‫ﻣﺜﻞ‬ PHP.‫ﺗُﺴﺘﺨﺪم اﳌﺸﻐﻼت ﻹﺟﺮاء ﻋﻤﻠﻴﺎت ﻋﲆ اﳌﺘﻐ ات واﻟﻘﻴﻢ‬  Relational operations. ‫ﻫﻨﺎك اﻟﻌﺪﻳﺪ ﻣﻦ أﻧﻮاع ﻋﻤﻠﻴﺎت‬.‫اﻟﻌﻤﻠﻴﺎت اﻹﺳﻨﺎدﻳﺔ‬.‫ﻋﻤﻠﻴﺎت اﻟﺤﺴﺎﺑﺎت‬  Boolean operations..‫اﻟﻌﻤﻠﻴﺎت اﻟﻌﻼﺋﻘﻴﺔ‬.‫اﻟﻌﻤﻠﻴﺎت اﳌﻨﻄﻘﻴﺔ‬ Operations(Attributive operations).. Known as assignment operators. :" " PHP Are used with numeric values to write a value to a variable. :{ $x = 10 } $x 10. :"="The basic assignment operator in PHP is  It means that the left operand gets set to the value of the assignment expression on the right, like:{ $x = 10 }, the value of $x is 10. Operations like:  Addition Example(Addition): Example(Subtraction): Example(Multiplication): Example(Division): Example(Modulus): ?> ?> ?> ?>  Modulus Output: Output: Output: Output: Output: 120 20 30 2 3 Operations(Calculations operations).‫ﺗُﻌﺮف ﺑﺎﺳﻢ اﻟﻌﻮاﻣﻞ اﻟﺤﺴﺎﺑﻴﺔ‬.‫ﺗُﺴﺘﺨﺪم ﻣﻊ اﻟﻘﻴﻢ اﻟﻌﺪدﻳﺔ‬ Known as arithmetic operators. :‫ﺗ ُﺴﺘﺨﺪم ﻹﺟﺮاء ﻋﻤﻠﻴﺎت ﺣﺴﺎﺑﻴﺔ ﻣﺜﻞ‬ Are used with numeric values. Are used to perform arithmetical operations like : Example(Addition): Example(Subtraction): Example(Multiplication): Example(Division):  Addition  Subtraction ?> ?> ?> Output: Output: Output: Output: 12 8 20 5 Operations(Relational operations).‫ﺗ ُﻌﺮف ﺑﺎﺳﻢ ﻋﻮاﻣﻞ اﳌﻘﺎرﻧﺔ‬ Known as comparison operators..(‫ﺗُﺴﺘﺨﺪم ﳌﻘﺎرﻧﺔ ﻗﻴﻤﺘ )رﻗﻢ أو ﺳﻠﺴﻠﺔ‬.:‫ﻋﻮاﻣﻞ ﻣﺜﻞ‬ Are used to compare two values (number or string). Operators like: Example(Equal): Example(Not equal): Example(Greater than): Example(Less than):  Equal  //returns true -> $x is less than $y ?> ?> ?> Output: Output: Output: Output: bool(true) bool(false) bool(true) bool(true) Operations(Boolean operations) Known as logical operators..‫ﺗ ُﻌﺮف ﺑﺎﺳﻢ اﳌﺸﻐﻼت اﳌﻨﻄﻘﻴﺔ‬.‫ﺗُﺴﺘﺨﺪم ﻟﺪﻣﺞ اﻟﻌﺒﺎرات اﻟﴩﻃﻴﺔ‬ :‫اﳌﺸﻐﻼت‬ Are used to combine conditional statements..‫ﺻﺤﻴ ًﺤﺎ‬ y$ ‫ أو‬x. ‫ﺻﺤﻴﺤ‬ Operators : $ ‫ ﺻﺤﻴﺢ إذا ﻛﺎن إﻣﺎ‬:‫أو‬y$‫ و‬x$ ‫إذا ﻛﺎن ﻛﻞ ﻣﻦ‬ ‫ ﺻﺤﻴﺢ‬:‫و‬Xor: ‫ ﺻﺤﻴﺢ إذا ﻛﺎن إﻣﺎ‬$x ‫ أو‬$y..‫ ﺻﺤﻴ ًﺤﺎ‬x. ‫ وﻟﻜﻦ ﻟﻴﺲ ﻛﻼﻫ‬،‫ﺻﺤﻴ ًﺤﺎ‬ Example(And): Example(Or): $ ‫ ﺻﺤﻴﺢ إذا ﻳﻜﻦ‬:‫ﻟﻴﺲ‬ Example(Xor): Example(Not):  And: True if both $x and $y ?> ?> ?> true, but not both.  Not:True if $x is not true. Output: Output: Output: Output: Hello world! Hello world! Hello world! Hello world! Print codes There are many ways to get output in PHP like:  echo :‫ﻣﺜﻞ‬  print PHP ‫ﻫﻨﺎك اﻟﻌﺪﻳﺪ ﻣﻦ اﻟﻄﺮق ﻟﻠﺤﺼﻮل ﻋﲆ اﻟﻨﺎﺗﺞ ﰲ‬echo print printf  printf sprintf  sprintf. ‫ ﻜﻦ اﺳﺘﺨﺪام اﳌﺘﻐ ات داﺧﻞ‬،‫إذا ﺗﻢ اﺳﺘﺨﺪام ﻋﻼﻣﺎت اﻻﻗﺘﺒﺎس اﳌﺰدوﺟﺔ‬ Print codes(echo) ‫ﺗﻌﺒ اﻟﻨﺺ‬HTML)(..‫ﻻ ﻳﺤﺘﻮي ﻋﲆ ﻗﻴﻤﺔ إرﺟﺎع‬.‫ﻜﻦ أن ﻳﺄﺧﺬ ﻣﻌﻠ ت ﻣﺘﻌﺪدة‬ ‫ ﻜﻦ أن ﻳﺤﺘﻮي اﻟﻨﺺ ﻋﲆ ﺗﻌﺒ ات‬echo ‫ أو‬echo :‫ﻜﻦ اﺳﺘﺨﺪاﻣﻪ ﻣﻊ أو ﺑﺪون أﻗﻮاس‬ Example: If double quotes are used, variables can be used inside the Output: string expression. PHP is Fun! Hello world! Number is : 10 This string was made with multiple parameters. 15 Print codes(print) Example:.HTML.‫ ﻟﺬا ﻜﻦ اﺳﺘﺨﺪاﻣﻪ ﰲ اﻟﺘﻌﺒ ات‬،.‫ﻜﻦ أن ﻳﺄﺧﺬ وﺳﻴﻄﺔ واﺣﺪة‬ String can contain HTML expressions. Output: PHP is Fun! Hello world! 15 printf(format,arg1,arg2,arg++). ‫ﻳﻌﺮض ﺳﻠﺴﻠﺔ ﻣﻨﺴﻘﺔ ﻣﻦ وﺳﻴﻄﺔ واﺣﺪة أو أﻛ‬ :‫ﺑﻨﺎء اﻟﺠﻤﻠﺔ‬format: ‫ ﻳﺤﺪد اﻟﺴﻠﺴﻠﺔ وﻛﻴﻔﻴﺔ ﺗﻨﺴﻴﻖ اﳌﺘﻐ ات ﻓﻴﻬﺎ‬.‫ﻣﻄﻠﻮب‬. Print codes(printf) arg1: ‫ اﻷوﱃ ﰲ ﺳﻠﺴﻠﺔ اﻟﺘﻨﺴﻴﻖ‬% ‫ اﻟﻮﺳﻴﻄﺔ اﻟﺘﻲ ﺳﻴﺘﻢ إدراﺟﻬﺎ ﻋﻨﺪ ﻋﻼﻣﺔ‬.‫ﻣﻄﻠﻮب‬. arg2: ‫ اﻟﺜﺎﻧﻴﺔ ﰲ ﺳﻠﺴﻠﺔ اﻟﺘﻨﺴﻴﻖ‬% ‫ اﻟﻮﺳﻴﻄﺔ اﻟﺘﻲ ﺳﻴﺘﻢ إدراﺟﻬﺎ ﻋﻨﺪ ﻋﻼﻣﺔ‬.‫اﺧﺘﻴﺎري‬. arg++: ‫ اﻟﺜﺎﻟﺜﺔ واﻟﺮاﺑﻌﺔ وﻣﺎ إﱃ ذﻟﻚ ﰲ‬% ‫ اﻟﻮﺳﻴﻄﺔ اﻟﺘﻲ ﺳﻴﺘﻢ إدراﺟﻬﺎ ﻋﻨﺪ ﻋﻼﻣﺔ‬.‫اﺧﺘﻴﺎري‬ ‫( ﰲ اﻟﺴﻠﺴﻠﺔ اﻟﺮﺋﻴﺴﻴﺔ‬%) ‫ ﻋﻨﺪ ﻋﻼﻣﺎت اﻟﻨﺴﺒﺔ اﳌﺌﻮﻳﺔ‬++‫ و‬arg2‫ و‬arg1.‫ﺳﻠﺴﻠﺔ اﻟﺘﻨﺴﻴﻖ‬ ‫ﺳﻴﺘﻢ إدراج ﻣﻌﻠ ت‬ It displays a formatted string from one or more arguments. Syntax : printf(format,arg1,arg2,arg++)  format : Required. Specifies the string and how to format the variables in it.  arg1 : Required. The argument to be inserted at the first %-sign in the format string.  arg2 : Optional. The argument to be inserted at the second %-sign in the format string.  arg++ : Optional. The argument to be inserted at the third, fourth, etc. %-sign in the format string.  The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. Example: Print codes(sprintf) It writes a formatted string to a variable. Syntax : sprintf(format,arg1,arg2,arg++)  format Required. Specifies the string and how to format the variables in it.  arg1 : Required. The argument to be inserted at the first %-sign in the format string  arg2 Optional. The argument to be inserted at the second %-sign in the format string.  arg++ : Optional. The argument to be inserted at the third, fourth, etc. %-sign in the format string.  The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string Example: Structural control tools Control structures in PHP are fundamental programming concepts that enable developers to write efficient code. The most common control structures used in PHP are if-else statements, loops such as for and while loops, and switch statements. Structural control tools: PHP. PHP if-else  Condition tools (if-if else-elseif-switch). for while switch. :  Rotation tools (for-while-do while).  Turning tools (break-continue). (if-if else-elseif-switch). (for-while-do while). (break-continue). Condition tools (if statement) Example: The if statement executes some code if one condition is true. Output: I am using if statement Condition tools (if…else statement) The if...else statement executes some code if a condition is Example: Output: x greater than 10 Condition tools (if...elseif...else Statement) The if...elseif...else statement executes different codes Example: for more than two conditions. } else { code to be executed if all conditions are false; } Output: x equals 10 Condition tools (Switch) Example: Switch is used to perform different actions based on... default: code to be executed if n is different from all labels; Output: } Your favorite color is red! Rotation tools (for) The for loop is used when you know how many times Example: the script should run.  init counter: Initialize the loop counter value Output:  test counter: Evaluated for each loop iteration. If it evaluates to The number is: 0 The number is: 1 TRUE, the loop continues. If it evaluates to FALSE, the loop ends. The number is: 2 The number is: 3  increment counter: Increases the loop counter value Rotation tools (while) The while loop executes a block of code Example: as long as the specified condition is true. Output: The number is: 1 The number is: 2 The number is: 3 Rotation tools (do while) Example: The do...while loop - loops through a block of code once, and } while (condition is true); Output: The number is: 1 The number is: 2 The number is: 3 Turning tools (break) The break statement can be used to jump out of a loop. Also, it used to jump out of a switch statement. Example with (for loop): Example with (while loop): } ?> Turning tools (continue) The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop. Example with (for loop): Example with (while loop): } ?> The End ‫اﻟﻣﻣﻠﻛﺔ اﻟﻌرﺑﯾﺔ اﻟﺳﻌودﯾﺔ‬ ‫وزارة اﻟﺗﻌﻠﯾم‬ ‫ﺟﺎﻣﻌﺔ اﻹﻣﺎم ﻣﺣﻣد ﺑن ﺳﻌود اﻹﺳﻼﻣﯾﺔ‬ ‫اﻟﻛﻠﯾﺔ اﻟﺗطﺑﯾﻘﯾﺔ‬ ‫‪Function in PHP‬‬ ‫‪Advanced Web programming CS211‬‬ ‫‪Modather A. Mustafa‬‬ Outlines qConcept of Functions qFunctions in PHP § Built-in Functions o Built-in Functions - Examples § User-Defined Functions o User-Defined Functions examples o passing parameters o return value o Default parameters values qCreating functions Modules oCreating functions Modules - example.‫ اﻟﻮﻇﻴﻔﺔ ﻋﺒﺎرة ﻋﻦ ﻛﺘﻠﺔ ﻣﻦ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ ﻗﺎﺑﻠﺔ ﻹﻋﺎدة اﻻﺳﺘﺨﺪام وﻣﺴﺘﻘﻠﺔ ﺗﺆدي ﻣﻬﻤﺔ أو ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﳌﻬﺎم اﳌﺤﺪدة‬،‫ﰲ اﻟﱪﻣﺠﺔ‬ ‫ ﺗﻘﺒﻞ ﻣﻌﻠ ت اﻹدﺧﺎل وﺗﻌﺎﻟﺠﻬﺎ وﺗﻌﻴﺪ ﻋﺎد ًة‬ Concept of Functions.‫ﻧﺘﻴﺠﺔ‬.‫ ﺗﺴﺎﻋﺪ اﻟﻮﻇﺎﺋﻒ ﰲ ﺗﻨﻈﻴﻢ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ وﺗﺤﺴ ﻗﺎﺑﻠﻴﺔ اﻟﻘﺮاءة وﺗﺴﻬﻴﻞ إﻋﺎدة اﺳﺘﺨﺪام اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ ﻣﻦ ﺧﻼل ﺗﻐﻠﻴﻒ اﻟﻮﻇﺎﺋﻒ ﰲ وﺣﺪات ﻣﻌﻴﺎرﻳﺔ‬ In programming, a function is a reusable and self-contained block of code that performs a specific task or set of tasks. It accepts input parameters, processes them, and typically returns a result. Functions help organize code, improve readability, and facilitate code reuse by encapsulating functionality into modular units. Functions in PHP In PHP, a function is a block of reusable code that performs a specific task. there are many type of functions in PHP : Built-in Functions: PHP comes with a wide range of built-in functions, it is preset and ready to use functions such as strlen(), print(), time() , etc..‫)( وﻣﺎ إﱃ ذﻟﻚ‬ :‫ اﻟﻮﻇﺎﺋﻒ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ اﳌﺴﺘﺨﺪم‬.‫ﻳﻘﻮم اﳌﻄﻮرون ﺑﺈﻧﺸﺎء وﻇﺎﺋﻔﻬﻢ اﻟﺨﺎﺻﺔ ﻟﻠﻤﻬﺎم اﳌﺨﺼﺼﺔ‬time‫)( و‬print‫)( و‬strlen ‫ وﻫﻲ وﻇﺎﺋﻒ ﻣﻌﺪة ﻣﺴﺒﻘًﺎ وﺟﺎﻫﺰة ﻟﻼﺳﺘﺨﺪام ﻣﺜﻞ‬،‫اﳌﻀﻤﻨﺔ‬ User-Defined Functions: ‫ ﻣﻊ ﻣﺠﻤﻮﻋﺔ واﺳﻌﺔ ﻣﻦ اﻟﻮﻇﺎﺋﻒ‬PHP: :‫ اﻟﻮﻇﺎﺋﻒ اﳌﻀﻤﻨﺔ‬ ‫ﻳﺄ‬PHP.‫ اﻟﻮﻇﻴﻔﺔ ﻋﺒﺎرة ﻋﻦ ﻛﺘﻠﺔ ﻣﻦ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ اﻟﻘﺎﺑﻠﺔ ﻹﻋﺎدة اﻻﺳﺘﺨﺪام واﻟﺘﻲ ﺗﺆدي ﻣﻬﻤﺔ ﻣﺤﺪدة‬، Developers create their own functions for custom tasks. Built-in Functions PHP provides a rich set of built-in functions that perform various tasks, ranging from string manipulation to mathematical operations and so on. These functions are readily available for use without the need for additional declarations. Leveraging built-in functions can significantly simplify code and enhance productivity..‫ ﺑﺪ ًءا ﻣﻦ ﻣﻌﺎﻟﺠﺔ اﻟﺴﻼﺳﻞ إﱃ اﻟﻌﻤﻠﻴﺎت اﻟﺤﺴﺎﺑﻴﺔ وﻣﺎ إﱃ ذﻟﻚ‬،‫ﻣﺠﻤﻮﻋﺔ ﻏﻨﻴﺔ ﻣﻦ اﻟﻮﻇﺎﺋﻒ اﳌﻀﻤﻨﺔ اﻟﺘﻲ ﺗﺆدي ﻣﻬﺎ ًﻣﺎ ﻣﺨﺘﻠﻔﺔ‬.‫ ﺗﺘﻮﻓﺮ ﻫﺬه اﻟﻮﻇﺎﺋﻒ ﺑﺴﻬﻮﻟﺔ ﻟﻼﺳﺘﺨﺪام دون اﻟﺤﺎﺟﺔ إﱃ إﻋﻼﻧﺎت إﺿﺎﻓﻴﺔ‬.‫ ﻜﻦ أن ﻳﺆدي اﻻﺳﺘﻔﺎدة ﻣﻦ اﻟﻮﻇﺎﺋﻒ اﳌﻀﻤﻨﺔ إﱃ ﺗﺒﺴﻴﻂ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ ﺑﺸﻜﻞ ﻛﺒ وﺗﻌﺰﻳﺰ اﻹﻧﺘﺎﺟﻴﺔ‬PHP ‫ﺗﻮﻓﺮ ﻟﻐﺔ‬ strlen() ‫ﺗﻌﻴﺪ ﻃﻮل اﻟﺴﻠﺴﻠﺔ‬ str_replace() ‫ﺗﺴﺘﺒﺪل ﺗﻜﺮارات ﺳﻠﺴﻠﺔ ﻓﺮﻋﻴﺔ ﺑﺄﺧﺮى‬. Built-in Functions String Manipulation : responsible of manipulating Strings substr() ‫ﺗﻌﻴﺪ ﺟﺰ ًءا ﻣﻦ اﻟﺴﻠﺴﻠﺔ‬. strtoupper() ‫ﺗﺤﻮل اﻟﺴﻠﺴﻠﺔ إﱃ أﺣﺮف ﻛﺒ ة‬. strtolower() ‫ﺗﺤﻮل اﻟﺴﻠﺴﻠﺔ إﱃ أﺣﺮف ﺻﻐ ة‬. Function Description Example Usage Function Result $length = strlen("Hello, strlen() Returns the length of a string. World!"); 12 - Length of the string. $newString = Replaces occurrences of a "Hello, PHP!" - Modified str_replace() substring with another. str_replace("world", "PHP", string. "Hello, world!"); $substring = substr("Hello, substr() Returns a portion of a string. World!", 0, 5); "Hello" - Extracted substring. Converts a string to $uppercase = “HELLO, WORLD!" – strtoupper() upperrcase. strtoupper("Hello, World!"); uppercase string. $lowercase = "hello, world!" - Lowercased strtolower() Converts a string to lowercase. strtolower("Hello, World!"); string. Built-in Functions - Examples $length = strlen("Hello, World!"); $newString = str_replace("world", "PHP", "Hello, world!"); $uppercase = strtoupper("Hello, World!"); $lowercase = strtolower("Hello, World!"); echo (" length: ".$length); Output : echo (" newString: ".$newString); echo (" uppercase: ".$uppercase); echo (" lowercase: ".$lowercase); Built-in Functions Variables Manipulation: responsible of manipulating variable in a php script Function Description Example Usage Function Result Checks if a variable is set and not if(isset($variable)) { } otherwise. isset() ‫ﺗﺘﺤﻘﻖ ﻣ إذا ﻛﺎن اﳌﺘﻐ ﻣﻀﺒﻮﻃًﺎ وﻟﻴﺲ ﻓﺎرﻏًﺎ‬ unset() Unsets/delete a variable. unset($variable); - unset() ‫ﺣﺬف ﻣﺘﻐ‬/ ‫إﻟﻐﺎء ﺗﻌﻴ‬. empty() ‫ﺗﺘﺤﻘﻖ ﻣ إذا ﻛﺎن اﳌﺘﻐ ﻓﺎرﻏًﺎ‬. gettype() ‫ﻳﺤﺼﻞ ﻋﲆ ﻧﻮع اﳌﺘﻐ‬. settype() ‫ﻳﻀﺒﻂ ﻧﻮع اﳌﺘﻐ‬. if(empty($variable)) { } otherwise. String - Variable type (e.g., gettype() Gets the type of a variable. $type = gettype($variable); "string", "integer"). $number = "123"; $number - Variable converted settype() Sets the type of a variable. settype($number, "int"); to an integer. $x = 15; Built-in Functions - Examples if(isset($x)) { echo "x is set value = ".$x; echo " type of x : ".gettype($x); } settype($x,"float"); echo " type of x : ".gettype($x); $x=null; Output : if(empty($x)) { echo " x is now empty"; } unset($x); if(isset($x)) { echo " x is set value = ".$x; }else{ echo " x is not set "; } date() ‫ﺗﻨﺴﻴﻖ اﻟﺘﺎرﻳﺦ واﻟﻮﻗﺖ اﻟﺤﺎﻟﻴ‬ time() ‫ إرﺟﺎع اﻟﻄﺎﺑﻊ اﻟﺰﻣﻨﻲ اﻟﺤﺎﱄ ﻟﻨﻈﺎم اﻟﺘﺸﻐﻴﻞ‬Unix. Built-in Functions Date Manipulation: responsible of manipulating Date and time format Function Description Example Usage Function Result Formats the current date and $formattedDate = date("Y-m- e.g., "2023-12-05 15:30:00" - date() time. d H:i:s"); Formatted date string. Current Unix timestamp. Returns the current Unix $timestamp = time(); * Usually used with date() time() timestamp. function : date('H:i:s',time()) Note : The Unix timestamp is a common way to handle dates and times in computing because it provides a consistent reference point, and it is not affected by time zones or daylight saving time changes. It is the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970. Built-in Functions - Examples echo 'Current Date : '.date("y-m-d , H:i:s"); echo 'Current Date : '.date("Y-m-d , H:i:s"); echo 'Current Date : '.date("Y-M-d , H:i:s"); echo 'Current Date : '.date("Y-M-D , H:i:s"); echo 'Current Date : '.date("Y-M-D , h:i:s"); Output : echo 'Current Time : '.date('h:i:s',time()); echo 'Current Time : '.date('H:I:s',time()); echo 'Current Time : '.date('H:i:a',time()); echo 'Current Time : '.date('H:i:A',time()); define() ‫ﻳﺤﺪد ﺛﺎﺑﺘًﺎ ﺑﺎﺳﻢ وﻗﻴﻤﺔ ﻣﺤﺪدﻳﻦ‬. defined() ‫ﻳﺘﺤﻘﻖ ﻣ إذا ﻛﺎن ﻫﻨﺎك ﺛﺎﺑﺖ ﻣﻌ‬ Built-in Functions.‫ﻣﺴﻤﻰ ﻣﻮﺟﻮدًا‬ include() ‫ﻳﺘﻀﻤﻦ اﳌﻠﻒ‬.‫اﳌﺤﺪد وﻳﻘﻴﻤﻪ‬ Generic Functions require() ‫ﻳﺘﻀﻤﻦ اﳌﻠﻒ‬.‫اﳌﺤﺪد وﻳﻘﻴﻤﻪ‬ htmlentities() ‫إﱃ‬ Function Description Example Usage Function Result.‫ﻛﻴﺎﻧﺎت‬HTML‫ﻳﺤﻮل اﻷﺣﺮف ذات اﳌﻌﻨﻰ‬ ‫اﻟﺨﺎص ﰲ‬ Defines a constant with a Constant PI is defined with define() specified name and value. define("PI", 3.14); the value 3.14. Checks whether a given if(defined("MY_CONSTANT")) { Boolean - true if defined, false defined() named constant exists. } otherwise Includes and evaluates the Code from "header.php" is include() specified file. include "header.php"; included and executed. Includes and evaluates the Code from "config.php" is require() specified file. require "config.php"; included and executed. Converts characters with $text = "alert('Hello, $encodedText contains the htmlentities() special meaning in HTML to World!');";$encode HTML-encoded version of entities. dText = htmlentities($text); $text. Built-in Functions Generic Functions :‫ﻣﻼﺣﻈﺎت‬ Ø `include() function` ً‫أﻛ ﺗﺴﺎﻫﻼً وﺗﺴﻤﺢ ﻟﻠﱪﻧﺎﻣﺞ اﻟﻨﴢ ﺑﺎﻻﺳﺘﻤﺮار ﺣﺘﻰ إذا ﻛﺎن اﳌﻠﻒ اﳌﻀﻤﻦ ﻣﻔﻘﻮدًا أو واﺟﻪ ﺧﻄﺄ‬. Ø `require() function` ‫ ﻣ ﻳﻮﻗﻒ اﻟﱪﻧﺎﻣﺞ اﻟﻨﴢ إذا ﻳﺘﻢ اﻟﻌﺜﻮر ﻋﲆ اﳌﻠﻒ اﳌﻄﻠﻮب أو اﺣﺘﻮى ﻋﲆ ﺧﻄﺄ‬،‫أﻛ ﴏاﻣﺔ وﺗﻮﻟﺪ ﺧﻄﺄً ﻓﺎد ًﺣﺎ‬. Notes : Ø ‫` ﺗﺸﺒﻪ اﻟﺪاﻟﺘﺎن‬include_once()` ‫`و‬require_once()` ‫ ﰲ‬PHP ‫` إﱃ ﺣﺪ ﻛﺒ‬include()` ‫ ﺣﺘﻰ إذا ﺗﻢ اﺳﺘﺪﻋﺎء اﻟﺪاﻟﺔ ﻋﺪة ﻣﺮات‬،‫ ﻓﻬﻲ ﺗﻀﻤﻦ ﺗﻀﻤ اﳌﻠﻒ أو ﻃﻠﺒﻪ ﻣﺮة واﺣﺪة ﻓﻘﻂ‬:‫ وﻟﻜﻦ ﻣﻊ ﻣﻴﺰة إﺿﺎﻓﻴﺔ‬،‫)(` ﻋﲆ اﻟﺘﻮاﱄ‬require`‫و‬ Ø `include() function` is more lenient and allows the script to continue even if the included file is missing or encounters an error. Ø `require() function` is stricter and generates a fatal error, stopping the script if the required file is not found or contains an error. Ø The `include_once()` and `require_once()` functions in PHP are very similar to `include()` and `require()`, respectively, but with an additional feature: they ensure that a file is included or required only once, even if the function is called multiple times Built-in Functions - Examples define("PI",3.1415); $papagraph = ' this is paragraph as is , with HTML define("E",2.71828); Entities ' ; $radius = 20; echo htmlentities($papagraph).""; $circle_area = 0 ; echo "without HTML Entities $papagraph"; if(defined("PI")){ $circle_area = PI*$radius*$radius; } echo "Circle Area when Radius = $radius is $circle_area"; Output : Output : User-Defined Functions User-Defined Function is a function defined by the developer to do some Task It is defined using the function keyword, followed by a name, a list of parameters (if any), and a block of code enclosed in curly braces as follows : ‫ ﻣﺘﺒﻮﻋﺔ ﺑﺎﺳﻢ وﻗﺎ ﺔ ﺑﺎﳌﻌﻠ ت‬، function functionName($param1, $param2,...) { :‫)إن وﺟﺪت( وﻛﺘﻠﺔ ﻣﻦ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ ﻣﺤﺎﻃﺔ ﺑﺄﻗﻮاس ﻣﺘﻌﺮﺟﺔ ﻋﲆ اﻟﻨﺤﻮ اﻟﺘﺎﱄ‬ function‫اﻟﻮﻇﺎﺋﻒ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ اﳌﺴﺘﺨﺪم‬ ‫ اﻟﻮﻇﻴﻔﺔ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ اﳌﺴﺘﺨﺪم ﻫﻲ وﻇﻴﻔﺔ ﻳﺤﺪدﻫﺎ اﳌﻄﻮر ﻟﻠﻘﻴﺎم ﺑﺒﻌﺾ اﳌﻬﺎم‬ // code to be executed ‫ ﻳﺘﻢ ﺗﻌﺮﻳﻔﻬﺎ ﺑﺎﺳﺘﺨﺪام اﻟﻜﻠﻤﺔ اﻷﺳﺎﺳﻴﺔ‬function functionName($param1, $param2,...) { ‫ اﻟﺘﻌﻠﻴ ت اﻟﱪﻣﺠﻴﺔ اﻟﺘﻲ ﺳﻴﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ‬// ] return $result;‫ ﻋﺒﺎرة إرﺟﺎع اﺧﺘﻴﺎرﻳﺔ‬// [ [ return $result;] // optional return statement functionName: ‫اﺳﻢ اﻟﻮﻇﻴﻔﺔ‬. } $param1, $param2: ‫اﳌﻌﻠ ت اﻟﺘﻲ ﻳﺘﻢ ﺮﻳﺮﻫﺎ إﱃ‬ } function. return: ‫ﻛﻠﻤﺔ أﺳﺎﺳﻴﺔ اﺧﺘﻴﺎرﻳﺔ ﻹرﺟﺎع ﻗﻴﻤﺔ‬ functionName: The name of the function. $param1, $param2: Parameters passed to the function. return: Optional keyword to return a value. User-Defined Functions Example User-Defined Functions – passing parameters In PHP, you can pass parameters to functions to provide data that the function can operate on. Parameters are values that are passed to a function when it is called. here is an improvement to previous example ‫ ﻜﻨﻚ ﺮﻳﺮ اﳌﻌﻠ ت إﱃ اﻟﻮﻇﺎﺋﻒ ﻟﺘﻮﻓ اﻟﺒﻴﺎﻧﺎت‬،.‫اﻟﺘﻲ ﻜﻦ ﻟﻠﻮﻇﻴﻔﺔ أن ﺗﻌﻤﻞ ﻋﻠﻴﻬﺎ‬ ‫ اﳌﻌﻠ ت ﻫﻲ اﻟﻘﻴﻢ اﻟﺘﻲ ﻳﺘﻢ ﺮﻳﺮﻫﺎ إﱃ اﻟﻮﻇﻴﻔﺔ ﻋﻨﺪ‬.‫اﺳﺘﺪﻋﺎﺋﻬﺎ‬ ‫ ﻓﻴ ﻳﲇ ﺗﺤﺴ ﻟﻠﻤﺜﺎل اﻟﺴﺎﺑﻖ‬PHP‫اﳌﺴﺘﺨﺪم – ﺮﻳﺮ اﳌﻌﻠ ت‬ ‫اﻟﻮﻇﺎﺋﻒ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ‬ ‫ ﰲ‬ User-Defined Functions – passing parameters Example User-Defined Functions – passing parameters Example : This example showcases a function with multiple parameters. The function `add` takes two parameters, calculates their sum, and echoes the result. User-Defined Functions – return value Functions can return values using the return keyword. The function `multiply` calculates the product of two numbers and returns the result. Example : User-Defined Functions – Default Values for Parameters.name$ ‫` ﻋﲆ ﻗﻴﻤﺔ اﻓﱰاﺿﻴﺔ ﳌﻌﻠﻤﺔ‬greet‫اﻟﻮﻇﺎﺋﻒ اﳌﺤﺪدة ﻣﻦ ﻗﺒﻞ اﳌﺴﺘﺨﺪم – اﻟﻘﻴﻢ اﻻﻓﱰاﺿﻴﺔ ﻟﻠﻤﻌﻠ ت‬ ` ‫ ﺗﺤﺘﻮي اﻟﺪاﻟﺔ‬.‫ﺗﺘﻴﺢ ﻟﻚ ﻗﻴﻢ اﳌﻌﻠ ت اﻻﻓﱰاﺿﻴﺔ ﺗﺤﺪﻳﺪ ﻗﻴﻤﺔ اﻓﱰاﺿﻴﺔ ﳌﻌﻠﻤﺔ ﻣﺎ إذا ﻳﺘﻢ ﺗﻮﻓ أي وﺳﻴﻄﺔ‬ Default parameter values allow you to specify a default value for a parameter if no argument is provided. The function `greet` has a default value for the $name parameter. Example : User-Defined Functions – Default Values for Parameters Example : Using Different Types of Parameters Creating functions Modules Creating function modules using the include() function is a common practice in PHP for organizing code into modular and reusable components. Modules are typically files containing related functions, and they can be included in other PHP scripts as needed..‫ أﺧﺮى ﺣﺴﺐ اﻟﺤﺎﺟﺔ‬PHP‫ﻟﺘﻨﻈﻴﻢ اﻟﻜﻮد إﱃ ﻣﻜﻮﻧﺎت وﺣﺪوﻳﺔ‬.‫وﻗﺎﺑﻠﺔ ﻹﻋﺎدة اﻻﺳﺘﺨﺪام‬ ‫ و ﻜﻦ ﺗﻀﻤﻴﻨﻬﺎ ﰲ ﻧﺼﻮص‬،‫ اﻟﻮﺣﺪات اﻟﻨﻤﻄﻴﺔ ﻫﻲ ﻋﺎد ًة ﻣﻠﻔﺎت ﺗﺤﺘﻮي ﻋﲆ وﻇﺎﺋﻒ ذات ﺻﻠﺔ‬PHP‫)( ﻫﻮ‬ ‫ﻣ رﺳﺔ ﺷﺎﺋﻌﺔ ﰲ‬include ‫إن إﻧﺸﺎء وﺣﺪات وﻇﻴﻔﻴﺔ ﺑﺎﺳﺘﺨﺪام اﻟﺪاﻟﺔ‬ Benefits of Using Function Modules 1.Modularity: Functions are organized into separate files, making the code modular and easier to manage. 2.Reusability: Functions can be reused across multiple scripts by including the module where needed. 3.Encapsulation: The module file encapsulates related functions, promoting a cleaner code structure..‫ ﻣ ﻳﻌﺰز ﺑﻨﻴﺔ اﻟﻜﻮد اﻷﻛ ﻧﻈﺎﻓﺔ‬،‫ ﻳﻐﻠﻒ ﻣﻠﻒ اﻟﻮﺣﺪة اﻟﻨﻤﻄﻴﺔ اﻟﻮﻇﺎﺋﻒ ذات اﻟﺼﻠﺔ‬:‫ اﻟﺘﻐﻠﻴﻒ‬.3‫ﻋﱪ ﻧﺼﻮص ﻣﺘﻌﺪدة ﻣﻦ ﺧﻼل‬ ‫ ﻜﻦ إﻋﺎدة اﺳﺘﺨﺪام اﻟﻮﻇﺎﺋﻒ‬:‫ إﻣﻜﺎﻧﻴﺔ إﻋﺎدة اﻻﺳﺘﺨﺪام‬..‫ﺗﻀﻤ اﻟﻮﺣﺪة اﻟﻨﻤﻄﻴﺔ ﻋﻨﺪ اﻟﺤﺎﺟﺔ‬ 2.‫ ﻣ ﻳﺠﻌﻞ اﻟﻜﻮد ﻄ ًﻴﺎ وأﺳﻬﻞ ﰲ اﻹدارة‬،‫ ﻳﺘﻢ ﺗﻨﻈﻴﻢ اﻟﻮﻇﺎﺋﻒ ﰲ ﻣﻠﻔﺎت ﻣﻨﻔﺼﻠﺔ‬:‫ اﻟﻮﺣﺪات اﻟﻨﻤﻄﻴﺔ‬. 1 Creating functions Modules - example functions.php Here's a step-by-step guide for creating a module called Creating functions Modules - example main_script.php Step 2: In your main PHP

Use Quizgecko on...
Browser
Browser