Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,157,920 members, 7,835,073 topics. Date: Tuesday, 21 May 2024 at 03:07 AM

Php Class For Beginners. Question Will Be Treated With High Priority. - Webmasters (2) - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Php Class For Beginners. Question Will Be Treated With High Priority. (35211 Views)

How Should Archive And Label Pages Be Treated? / Blogging Advice For Beginners / Designing A Website: For Beginners (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (13) (Reply) (Go Down)

Re: Php Class For Beginners. Question Will Be Treated With High Priority. by yawatide(f): 9:44pm On Dec 23, 2008
I am just starting an ajax script section on http://ds.mwebng.net/ [if u don't know what ajax is all about, don't bother visiting]

Now, dhtml, not a nice thing to say there, wouldn't you agree? I mean, were you born, no offense, with an ajax spoon in your mouth yourself?

- i don't mean to sound rude, but u just wont get it.
You don't know that for a fact. Just cos it might have taken you 30 seconds to learn ajax doesn't mean it won't take me 15 seconds.

Just do it and let the chips fall where they may.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 12:41pm On Dec 28, 2008
**** Edited wat i said earlier **** Happy New year guys.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 12:49pm On Dec 28, 2008
lol
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by xanadu: 5:13pm On Jan 02, 2009
??
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by xanadu: 9:59pm On Jan 02, 2009
dhtml:

**** Edited what i said earlier **** Happy New year guys.

My '??' comments above were a reaction to the comments you have now edited/deleted, good thing you did, well done.

Happy New Year!
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 8:34pm On Jan 03, 2009
And i have decided to carry learners along and also anyone else possible - Dynamic Web Design Tutorials Ft Javascript,Ajax,DOM,PHP,MySQL, - https://www.nairaland.com/nigeria/topic-213492.0.html - you will see that if you visit that my thread, and even went to the extent of creating some free softwares and web tools - and even the footer of my profile testify to that - i have turned over a new leaf - and even my site sef carry a tutorial section - i will discuss those scripts in the forum so ppl can benefit from them too - and happy new year to you all - and thanks Guys for shaking me up - it was for good - i was almost growin horns last year anyway - thanks to yawa and @moderator who talked some sense into my head.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by OmniPotens(m): 9:38pm On Jan 03, 2009
You've picked up now and remember the advice I gave you. You followed it well and things are getting to the point I pointed out too. What does it say of you? Good?

Boys are Boys and Men are Men!

Take it or leave it.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 7:33am On Jan 04, 2009
And this is a very useful thread, i will point people here to come and learn PHP, and i will be falling in here ever so often to answer any questions that may come up.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 1:25pm On Jan 05, 2009
Am back, and thanks for your comments and encouragement.

Today We are going to [size=8pt]Using Library Files[/size]
After you have created a function that does something useful, you will probably want to use it again in other scripts. Rather than copy the function definition into each script that needs to use it, you can use a library file so that your function needs to be stored and maintained in only one place.

Before you go any further, you should create a library file called tax.php that contains both the add_tax and add_tax_rate functions but no other PHP code.

Using Library Files A library file needs to enclose its PHP code inside <?php tags just like a regular script; otherwise, the contents will be displayed as HTML when they are included in a script.





Including Library Files
To incorporate an external library file into another script, you use the include keyword. The following includes tax.php so that add_tax can be called in that script:

include "tax.php";
$price = 95;
echo "Price before tax: $price <br>";
echo "Price after tax: ";
echo add_tax($price);



The include path Setting By default, include searches only the current directory and a few system locations for files to be included. If you want to include files from another location, you can use a path to the file.

You can extend the include path to include other locations without a path being required by changing the value of the include_path setting.





You can use the include_once keyword if you want to make sure that a library file is loaded only once. If a script attempts to define the same function a second time, an error will result. Using include_once helps to avoid this, particularly when files are being included from other library files. It is often useful to have a library file that includes several other files, each containing a few functions, rather than one huge library file.

Require The require and require_once instructions work in a similar way to include and include_once but have subtly different behavior. In the event of an error, include generates a warning, but the script carries on running as best it can. A failure from a require statement causes the script to exit immediately.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:10pm On Jan 19, 2009
In the last lesson you have learned how to use functions to modularize your code. In the next lesson you will learn about ways to work with numeric data in PHP.


Arithmetic
As you would expect, PHP includes all the basic arithmetic operators. If you have not used another programming language, the symbols used might not all be obvious, so we'll quickly run through the basic rules of arithmetic in PHP.

Arithmetic Operators
Addition is performed with the plus symbol (+). This example adds 6 and 12 together and displays the result:

echo 6 + 12;



Subtraction is performed with the minus symbol (-), which is also used as a hyphen. This example subtracts 5 from 24:

echo 24 - 5;



The minus symbol can also be used to negate a number (for example, 20).

Multiplication is performed with the asterisk symbol (*). This example displays the product of 4 and 9:

echo 4 * 9;



Division is performed with the forward slash symbol (/). This example divides 48 by 12:

echo 48 / 12;



Division When you divide two integers, the result is an integer if it divides exactly. Otherwise, it is a double. A fractional result is not rounded to an integer.





Modulus is performed by using the percent symbol (%). This example displays 3the remainder of 21 divided by 6:

echo 21 % 6;



Modulus The modulus operator can be used to test whether a number is odd or even by using $number % 2. The result will be 0 for all even numbers and 1 for all odd numbers (because any odd number divided by 2 has a remainder of 1).





Incrementing and Decrementing
In PHP you can increment or decrement a number by using a double plus (++) or double minus (--) symbol. The following statements both add one to $number:

$number++;

++$number;



The operator can be placed on either side of a variable, and its position determines at what point the increment takes place.

This statement subtracts one from $countdown before displaying the result:

echo --$countdown;



However, the following statement displays the current value of $countdown before decrementing it:

echo $countdown--;



The increment and decrement operators are commonly used in loops. The following is a typical for loop, using a counter to repeat a section of code 10 times:

for ($count=1; $count<=10; $count++) {
echo "Count = $count<br>";
}



In this case, the code simply outputs the value of $count for each pass of the loop.

Compound Operators
Compound operators provide a handy shortcut when you want to apply an arithmetic operation to an existing variable. The following example uses the compound addition operator to add six to the current value of $count:

$count += 6;



The effect of this is to take the initial value of $count, add six to it, and then assign it back to $count. In fact, the operation is equivalent to doing the following:

$count = $count + 6;



All the basic arithmetic operators have corresponding compound operators, as shown in Table 5.1.

Table 5.1. Compound Operators

Operator Equivalent To

$a += $b $a = $a + $b;

$a -= $b $a = $a - $b;

$a *= $b $a = $a * $b;

$a /= $b $a = $a / $b;

$a %= $b $a = $a % $b;





Operator Precedence
The rules governing operator precedence specify the order in which expressions are evaluated. For example, the following statement is ambiguous:

echo 3 * 4 + 5;



Are 3 and 4 multiplied together, and then 5 is added to the result, giving a total of 17? Or are 4 and 5 added together first and multiplied by 3, giving 27? Running this statement in a script will show you that in PHP, the result is 17.

The reason is that multiplication has a higher precedence than addition, so when these operators appear in the same expression, multiplication takes place first, using the values that immediately surround the multiplication operator.

To tell PHP that you explicitly want the addition to take place first, you can use parentheses, as in the following example:

echo 3 * (4 + 5);



In this case, the result is 27.

In PHP, the precedence of arithmetic operators follows the PEMDAS rule that you may have learned at school: parentheses, exponentiation, multiplication/division, and addition/subtraction.

The full operator precedence list for PHP, including many operators you haven't come across yet, can be found in the online manual at www.php.net/manual/en/language.operators.php.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Agoloj(m): 9:41pm On Jan 19, 2009
Hello quadrillio,
I really need to learn alot about the web, expecially in web hosting and domain names. I would prefer we talk one on one on this because, there are alot of silly question i might be asking you. I tried the number you dropped on your second lesson, but couldnt get through. Here is my email address ajluv77@yahoo.com, hope to get yours.

Jude
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 10:22am On Jan 20, 2009
Sorry about that, the Glo number I dropped on my second lesson is temporally unavailable till the end of this month. but u can call my MTN line anytime from 5pm cos the network in my office is a bit bad. my mail add is quadri20_wale @ yahoo.com am also online (but invisible most time).

Will continue mylesson later in the day.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by yawatide(f): 9:52pm On Jan 20, 2009
dhtml,

I think that if you start your ajax tutorial with a "hello world" type thing, it won't be as intimidating to ppl as you may think wink

Start off with "hello world" then a db example where you show how to insert and select data from a db and display via ajax. Don't even bother going to the more complex stuff (caching, history, etc) until you get a feel for how you are doing, courtesy of response from viewers.

Good luck!
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:46pm On Jan 21, 2009
Any misplace Here
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by iamok: 1:06pm On Jan 22, 2009
Thanks for the good job u r doing here.

Please, I'll like to have a code for uploading a file from joomla site to a specified email.

Waiting for your response as soon a spossible.

Thanks
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 4:06pm On Jan 27, 2009
iamok:

Thanks for the good job u r doing here.

Please, I'll like to have a code for uploading a file from joomla site to a specified email.

Waiting for your response as soon a spossible.

Thanks

can u explain more please
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:15pm On Jan 28, 2009
@aimok, As I wait for u to explain, cos whatever your question is everyone will learn from it.

I'll like to continue. Today

Numeric Data Types
You have already seen that PHP assigns a data type to each value and that the numeric data types are integer and double, for whole numbers.

To check whether a value is either of these types, you use the is_float and is_int functions. Likewise, to check for either numeric data type in one operation, you can use is_numeric.

The following example contains a condition that checks whether the value of $number is an integer:

$number = "28";
if (is_int($number)) {
echo "$number is an integer";
}
else {
echo "$number is not an integer";
}



Because the actual declaration of that variable assigns a string valuealbeit one that contains a numberthe condition fails.

Although $number in the previous example is a string, PHP is flexible enough to allow this value to be used in numeric operations. The following example shows that a string value that contains a number can be incremented and that the resulting value is an integer:

$number = "6";
$number++;
echo "$number has type " . gettype($number);



Understanding NULLs
The value NULL is a data type all to itselfa value that actually has no value. It has no numeric value, but comparing to an integer value zero evaluates to true:

$number = 0;
$empty=NULL;
if ($number == $empty) {
echo "The values are the same";
}



Type Comparisons If you want to check that both the values and data types are the same in a condition, you use the triple equals comparison operator (===).
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 3:15pm On Feb 02, 2009
Numeric Functions
Let's take a look at some of the numeric functions available in PHP.

Rounding Numbers
There are three different PHP functions for rounding a decimal number to an integer.

You use ceil or floor to round a number up or down to the nearest integer, respectively. For example, ceil(1.3) returns 2, whereas floor(6.cool returns 6.

Negative Rounding Note the way that negative numbers are rounded. The result of floor(-1.1) is-2the next lowest whole number numericallynot-1. Similarly, ceil(-2.5) returns -2.





To round a value to the nearest whole number, you use round. A fractional part under .5 will be rounded down, whereas .5 or higher will be rounded up. For example, round(1.3) returns 1, whereas round(1.5) returns 2.

The round function can also take an optional precision argument. The following example displays a value rounded to two decimal places:

$score = 0.535;
echo round($score, 2);



The value displayed is 0.54; the third decimal place being 5 causes the final digit to be rounded up.

You can also use round with a negative precision value to round an integer to a number of significant figures, as in the following example:

$distance = 2834;
echo round($distance, -2);



Comparisons
To find the smallest and largest of a group of numbers, you use min and max, respectively. These functions take two or more arguments and return the numerically lowest or highest element in the list, respectively.

This statement will display the larger of the two variables $a and $b:

echo max($a, $b);



There is no limit to the number of arguments that can be compared. The following example finds the lowest value from a larger set of values:

echo min(6, 10, 23, 3, 88, 102, 5, 44);



Not surprisingly, the result displayed is 3.

Random Numbers
You use rand to generate a random integer, using your system's built-in random number generator. The rand function optionally takes two arguments that specify the range of numbers from which the random number will be picked.

Random Limit The constant RAND_MAX contains the highest random number value that can be generated on your system. This value may vary between different platforms.





The following statement picks a random number between 1 and 10 and displays it:

echo rand(1, 10);



You can put this command in a script and run it a few times to see that the number changes each time it is run.

There is really no such thing as a computer-generated random number. In fact, numbers are actually picked from a very long sequence that has very similar properties to true random numbers. To make sure you always start from a different place in this sequence, you have to seed the random number generator by calling the srand function; no arguments are required.

Random Algorithms PHP includes another random number generator, known as Mersenne Twister, that is considered to produce better random results than rand. To use this algorithm, you use the functions mt_rand and mt_srand.





Mathematical Functions
PHP includes many mathematical functions, including trigonometry, logarithms, and number base conversions. As you will rarely need to use these in a web environment, those functions are not covered in this book.

To find out about a function that performs a specific mathematical purpose, refer to the online manual at www.php.net/manual/en/ref.math.php.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by foni2k4(m): 12:03am On Feb 06, 2009
Great job you have done here, hope to read more from you. And hope we will have more of this here too. Thanks
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 12:49pm On Feb 06, 2009
WORKING WITH STRING

In this lesson you will learn about some of the powerful string functions that are included in the PHP language.

Anatomy of a String

A string is a collection of characters that is treated as a single entity. In PHP, strings are enclosed in quotation marks, and you can declare a string type variable by assigning it a string that is contained in either single or double quotes.

The following examples are identical; both create a variable called $phrase that contains the phrase shown:

$phrase = "The sky is falling";
$phrase = 'The sky is falling';



Quote Characters Quotation marks in PHP do not point in a direction. The same symbol is used to start a string as to indicate the end. You must use two apostrophe characters (') around a single-quoted stringdo not use backtick characters (`).





Escaping Characters with Backslash
Double quotes can be used within single-quoted strings and vice versa. For instance, these string assignments are both valid:

$phrase = "It's time to party!";
$phrase = 'So I said, "OK"';



However, if you want to use the same character within a quoted string, you must escape that quote by using a backslash. The following examples demonstrate this:

$phrase = 'It\'s time to party!";
$phrase = "So I said, \"OK\"";



In the previous examples, if the backslash were not used, PHP would mismatch the quotes, and an error would result.

Which style of quoting you use largely depends on personal preference and, hopefully, a desire to create tidy code. Remember, though, as you saw in Lesson 2, "Variables," that a variable prefixed with a dollar sign inside a double-quoted string is replaced with its values, whereas in a single-quoted string, the dollar sign and variable name appear verbatim.

If you want a dollar sign to form part of a double-quoted string, you can also escape this by using a backslash. For example, the following two statements are equivalent:

$offer = 'Save $10 on first purchase';
$offer = "Save \$10 on first purchase";



Without the backslash, the second example would attempt to find the value of a variable called $10, which is, in fact, an illegal variable name.

The backslash character can also be used in a double-quoted string to indicate some special values inside strings. When followed by a three-digit number, it indicates the ASCII character with that octal value.

You can send the common nonprintable ASCII characters by using standard escape characters. A newline is \n, tab is \t, and so on. Refer to man ascii on your system or www.ascii.cl for a comprehensive list.

Concatenation
You have already seen how strings can be joined using the period symbol as a concatenation operator. A compound version of this operator, .=, can be used to append a string to an existing variable.

The following example builds up a string in stages and then displays the result:

$phrase = "I want ";
$phrase .= "to teach ";
$phrase .= "the world ";
$phrase .= "to sing";
echo $phrase;



The phrase appears as expected. Note the use of spaces after teach and world to ensure that the final string is correctly spaced.

Comparing Strings
You can compare string values simply by using the standard comparison operators. To check whether two strings are equal, you use the double equals (==) sign:

if ($password == "letmein"wink
echo "You have a guessable password";



The equality operator, when applied to strings, performs a case-sensitive comparison. In the previous example, any other capitalization of $password, such as LetMeIn, would not pass this test.

The inequality operators<, <=, >, and >=perform a comparison based on the ASCII values of the individual characters in the strings. The following condition could be used to divide people into two groups, based on their last namethose with names beginning AM and those beginning NZ:

if ($last_name < "N"wink
echo "You are in group 1";
else
echo "You are in group 2";



ASCII Values Because string comparisons are done on their underlying ASCII values, all lowercase letters have higher values than their equivalent uppercase letters. Letters az have values 97122, whereas AZ occupy values 6590.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 11:55am On Feb 11, 2009
I decided pause and listen to questions??

I'll be waiting
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by switch47(m): 12:28pm On Feb 11, 2009
@POST
WHICH SCRIPT IS NAIRALIST RUNNING ON??
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 3:52pm On Feb 11, 2009
To my best of knowledge, I think is PHP (don't mind the re-naming)

but from experience it's PHP
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 4:05pm On Feb 11, 2009
More questions please.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by yawatide(f): 4:17pm On Feb 11, 2009
Let's do some socratic deductions from the good old days of my uni philosophy and logic class, if you may:

Seun owns Nairaland, Nairaland runs on PHP, Seun owns Nairalist, Therefore Nairalist runs on,
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by switch47(m): 5:43pm On Feb 11, 2009
quadrillio:

More questions please.
does one have to write or create it or it is a ready made stuff like that of wordpress thing? how can one make something like that?
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by nitation(m): 6:59pm On Feb 11, 2009
@ Ya-wa-ti-de

PHP
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 11:48pm On Feb 11, 2009
php/mysql - i was testing out some scripts on nairaland once when an error occured and displayed php/mysql error codes on my browser - so as far as i know - it is running on php/mysql
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 1:56pm On Feb 12, 2009
@switch47
I have not made any research on it, so I can't say if it's a ready-made stuff.

but I can tell you that u can create one easily(if you are very good in designing database driven websites)

hope that answered your question

any more please
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by netm: 5:32pm On Feb 27, 2009
@Quadrillo, Please can you give me a-one-on one training? I live at Ojodu in Ikeja
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 8:37am On Feb 28, 2009
netm:

@Quadrillo, Please can you give me a-one-on one training? I live at Ojodu in Ikeja
So we are even in the same network.
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:45pm On Mar 03, 2009
netm:

@Quadrillo, Please can you give me a-one-on one training? I live at Ojodu in Ikeja

I can take u only on weekends(sat & sun)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (13) (Reply)

best BULK SMS provider in Nigeria ? / When You Are A Computer Guru And Your Girlfriend Needs Your Assistance / The Meaning Of CAPTCHA & 6 Types Of CAPTCHA

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 68
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.