Skip to main content

PHP Tutorial - Lesson 2: Introduction to PHP - Part III


Server Side Includes (SSI)

          In order to organize your work, and be a professional programmer, simplify your code. There are many things you could do, to organize your code, and facilitate development acceleration to your application.
          Here I’ll put some advices to you as a programmer that might help you in your job.
          First thing, simplify, and simplify… Make it easy. Your script should do only one job. This will facilitate handling errors.
          Second thing, it is not preferred that your function has more than three parameters to finish its job, this means that you can simplify it more.
          Use Loops only when needed.
          Don’t repeat your code.
          Divide your script in directories, and group codes that complete each other in the same directory.
          Use available (OPEN SOURCE Libraries) rather than build it yourself. This will save your time, and give your application more qualities. Remember “Don’t re-invent the wheels”.
          Finally, think of simplest and shortest ways to do your mission. Of course it should be legal methods.

          Suppose that in your application, there is a menu that you need to be showed in more than one page. Of course, you have not to copy and paste the menu in every page. What about if you want to add a new item to your menu? Shall you add to all pages copying and pasting!! It is not a programming idea.
          The best and logical thing is put your menu in a file, and call this file where needed.
How to accomplish this?
          Save your menu in a file.
          For example “menu.php”.
          At each page you need your menu to appear, call the file by using one of these two functions include() or require().
          Both functions are identical in their job, but, they differ in handling errors. include function will search for your file, if found it then will be included in your page, and so require. But if not found. If you used include, your script will continue working, and will not stop. Where require will show an error and your script completely will not work.
Example
<?php
require(“menu.php”);
include(“wrong.php”);
?>
          If menu is found, the script will continue working, but wrong file will not stop working your script.
          Where to use?
          If your script depends completely on the included file, then use require. Else use include.
          In my opinion, I prefer require.
End of Lesson 2.
To download this lesson as PDF click here: PHP Tutorial - Lesson 2: Introduction to PHP - Part III

Best Wishes,
Anas Jaghoub 

Comments

Popular posts from this blog

AABU GTUG Opening Event

On February 17, 2011 We’ve headed to Al Al Bayt University, to run one of the biggest event established there, for opening the AABU GTUG (Google’s Technologies Users Group). The event focused on introducing the GTUGS (Google’s Technologies Users Groups) and introducing Google’s technologies to students, such as Android and App Engine, to Chrome Extensions and HTML5 demos. Attendees exceeded 250 attendee, in addition to Vice president of Al Al Bayt University Dr. Hashem Al Masaeed, Deanship of College of I.T at Al Al Bayt University Prof. Ismail Ababneh, and a quite number of professors and teachers at the college of I.T at AABU, in addition to Yarmuk fm and Al Ro’aya  tv. AABU GTUG as a Google’s Technologies Users Group interested in Google’s technologies and tries as possible to increase students awareness about Google’s technologies, and introduce it to them. Their was a lot of activities during the event, beginning with the key note from me Anas Jaghoub, that included introducin...

تعلم تطوير تطبيقات للموبايل باستخدام الأندرويد

مرحبا أصدقائي يسعدني أن أبدأ معكم سلسلة حلقات في تعلم تطوير تطبيقات للموبايل باستخدام الأندرويد ، وسأسعى جاهدا معكم في أن تكون هذه السلسلة من أوائل السلسلات في اللغة العربية لتعليم برمجة تطبيقات الأندرويد من البداية وحتى الاحتراف. وسأحاول قدر المستطاع الشرح بلغة عربية بسيطة ومفهومة. حيث ستكون غدا إن شاء الله الحلقة الأولى من تعلم تطوير تطبيقات الموبايل باستخدام الأندرويد. أنس الجاغوب Twitter: @anasjaghoub Facebook: anasjaghoub

سلسلة تعلم برمجة تطبيقات الاندرويد – إنشاء أول تطبيق للاندرويد – الحلقة رقم 2

تحدثنا في الحلقة السابقة عن إعداد بيئة العمل، وأهم الأدوات والحزم اللازمة للبدء في تطوير تطبيقات لنظام التشغيل الاندرويد. سنتحدث في هذه الحلقة عن كيفية إنشاء تطبيق للاندرويد، وما هي مكونات تطبيق الاندرويد والبنية الهيكلية ﻷي تطبيق على الاندرويد. إنشاء تطبيق باستخدام بيئة العمل Netbeans : 1. اضغط على قائمة File 2. اختر New Project. 3. اختر نوع المشروع Android 4. اضغط زر Next. 5. اضبط إعدادات المشروع كالتالي: Project Name: اسم المشروع، يفضل أن يكون اسم المشروع هو نفس اسم التطبيق وذلك لتمييزه عن باقي المشاريع الأخرى Package Name: اسم حزمة المشروع، وهنا يجب اتباع قواعد تسمية الحزم في لغة Java إذ يجب أن تتكون من مقطعين على الأقل ويفصل بين كل مقطع بنقطة، ولا يوجد فراغات. Target Platform: رقم نسخة نظام التشغيل الاندرويد التي يدعمها هذا التطبيق، وهنا لا بد من اختيار أقل رقم يتوافق معه هذا التطبيق لمزيد من التفاصيل شاهد الصورة التالية: 6. اضغط على زر Finish وهكذا نكون قد أنشأنا بمساعدة بيئة العمل Netbeans أول تطبيق للأندرويد حيث تم تصميم هيكل التطبيق، واستدعاء كافة ال...