Stats: 3,190,905 members, 7,942,266 topics. Date: Saturday, 07 September 2024 at 05:05 AM |
Nairaland Forum / Science/Technology / Webmasters / Php Class For Beginners. Question Will Be Treated With High Priority. (35592 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 quadrillio(m): 11:16am On Jun 12, 2009 |
@DHTML, thanks 4 keepin my thread bubbling while I was busy, You're really a brother Incase there is any question on the script posted, pls voice out, Am back and better, lets go there String Functions Let's take a look at some of the other string functions available in PHP. The full list of string functions can be found in the online manual, at www.php.net/manual/en/ref.strings.php. Capitalization You can switch the capitalization of a string to all uppercase or all lowercase by using strtoupper or strtolower, respectively. The following example demonstrates the effect this has on a mixed-case string: $phrase = "I love PHP"; echo strtoupper($phrase) . "<br>"; echo strtolower($phrase) . "<br>"; The result displayed is as follows: I LOVE PHP i love php If you wanted to functions capitalize only the first character of a string, you use ucfirst: $phrase = "welcome to the jungle"; echo $ucfirst($phrase); You can also capitalize the first letter of each wordwhich is useful for namesby using ucwords: $phrase = "green bay packers"; echo ucwords($phrase); Neither ucfirst nor ucwords affects characters in the string that are already in uppercase, so if you want to make sure that all the other characters are lowercase, you must combine these functions with strtolower, as in the following example: $name = "CHRIS NEWMAN"; echo ucwords(strtolower($name)); Dissecting a String The substr function allows you to extract a substring by specifying a start position within the string and a length argument. The following example shows this in action: $phrase = "I love PHP"; echo substr($phrase, 3, 5); This call to substr returns the portion of $phrase from position 3 with a length of 5 characters. Note that the position value begins at zero, not one, so the actual substring displayed is ove P. If the length argument is omitted, the value returned is the substring from the position given to the end of the string. The following statement produces love PHP for $phrase: echo substr($phrase, 2); If the position argument is negative, substr counts from the end of the string. For example, the following statement displays the last three characters of the stringin this case, PHP: echo substr($phrase, -3); If you need to know how long a string is, you use the strlen function: echo strlen($phrase); To find the position of a character or a string within another string, you can use strpos. The first argument is often known as the haystack, and the second as the needle, to indicate their relationship. The following example displays the position of the @ character in an email address: $email = "chris@lightwood.net"; echo strpos($email, "@" ![]() String Positions Remember that the character positions in a string are numbered from the left, starting from zero. Position 1 is actually the second character in the string. When strpos finds a match at the beginning of the string compared, the return value is zero, but when no match is found, the return value is FALSE. You must check the type of the return value to determine this difference. For instance, the condition strpos($a, $b) === 0 holds true only when $b matches $a at the first character. The strstr function extracts a portion of a string from the position at which a character or string appears up to the end of the string. This is a convenience function that saves your using a combination of strpos and substr. The following two statements are equivalent: $domain = strstr($email, "@" ![]() $domain = strstr($email, strpos($email, "@" ![]() Like I said in the beginning am back and better. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 8:42pm On Jun 12, 2009 |
Welcome back bro. . . |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 6:49pm On Jun 14, 2009 |
Working with Arrays What Is an Array? An array is a variable type that can store and index a set of values. An array is useful when the data you want to store has something in common or is logically grouped into a set. Creating and Accessing Arrays The following PHP statement declares an array called $temps and assigns it 5 values that represent the temperatures for January through December: $temps = array(23, 33,11,13,70); The array $temps that is created contains 5 values that are indexed with numeric key values from 0 to 4. To reference an indexed value from an array, you suffix the variable name with the index key. To display, for example, you would use the following: echo $temps[2]; The square brackets syntax can also be used to assign values to array elements. To set a new value for another element, for instance, you could use the following: $temps[3] = 56; The array Function The array function is a shortcut function that quickly builds an array from a supplied list of values, rather than adding each element in turn. If you omit the index number when assigning an array element, the next highest index number will automatically be used. Starting with an empty array $temps, the following code would begin to build the same array as before: $temps[] = 38; $temps[] = 40; $temps[] = 49; , In this example, the value 38 would be assigned to $temps[0], 40 to $temps[1], and so on. If you want to make sure that these assignments begin with $temps[0], it's a good idea to initialize the array first to make sure there is no existing data in that array. You can initialize the $temps array with the following command: $temps = array(); Outputting the Contents of an Array PHP includes a handy function, print_r, that can be used to recursively output all the values stored in an array. The following script defines the array of temperature values and then displays its contents onscreen: $temps = array(38, 40, 49, 60, 70, 79, 84, 83, 76, 65, 54, 42); print "<PRE>"; print_r($temps); print "</PRE>"; The <PRE> tags are needed around print_r because the output generated is text formatted with spaces and newlines. The output from this example is as follows: Array ( [0] => 38 [1] => 40 [2] => 49 [3] => 60 [4] => 70 ) print_r The print_r function can be very useful when you're developing scripts, although you will never use it as part of a live website. If you are ever unsure about what is going on in an array, using print_r can often shed light on the problem very quickly. Looping Through an Array You can easily replicate the way print_r loops through every element in an array by using a loop construct to perform another action for each value in the array. By using a while loop, you can find all the index keys and their values from an arraysimilar to using the print_r functionas follows: while (list($key, $value) = each($temps)) { echo "Key $key has value $val <br>"; } For each element in the array, the index key value will be stored in $key and the value in $value. PHP also provides another construct for traversing arrays in a loop, using a foreach construct. Whether you use a while or foreach loop is a matter of preference; you should use whichever you find easiest to read. The foreach loop equivalent to the previous example is as follows: foreach($temps as $key => $value) { , } Loops You may have realized that with the $temps example, a for loop counting from 0 to 4could also be used to find the value of every element in the array. However, although that technique would work in this situation, the keys in an array may not always be sequential and, as you will see in the next section, may not even be numeric. Associative Arrays The array examples so far in this chapter have used numeric keys. An associative array allows you to use textual keys so that the indexes can be more descriptive. To assign a value to an array by using an associative key and to reference that value, you simply use a textual key name enclosed in quotes, as in the following examples: $temps["jan"] = 38; echo $temps["jan"]; To define the complete array of average monthly temperatures in this way, you can use the array function as before, but you indicate the key value as well as each element. You use the => symbol to show the relationship between a key and its value: $temps = array("jan" => 38, "feb" => 40, "mar" => 49, "apr" => 60, "may" => 70, "jun" => 79, "jul" => 84, "aug" => 83, "sep" => 76, "oct" => 65, "nov" => 54, "dec" => 42); The elements in an associative array are stored in the order in which they are defined (you will learn about sorting arrays later in this lesson), and traversing this array in a loop will find the elements in the order defined. You can call print_r on the array to verify this. The first few lines of output are as follows: Array ( [jan] => 38 [feb] => 40 [mar] => 49 , see u in the next class |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by mavtrevor(m): 12:00am On Jun 16, 2009 |
Cant wait for the next class. These tutorials are really nice as it help some of us understand little things we thought we know better. Keep them coming in bro. Thanks dhtml for your help in this forum. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 5:40am On Jun 16, 2009 |
u are welcome mav. You know, qadrillo and webdezzi are both my guys, so i am always following their tutorials too in case i need to make any contributions. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 8:44pm On Jun 18, 2009 |
Array Functions You have already seen the array function used to generate an array from a list of values. Now let's take a look at some of the other functions PHP provides for manipulating arrays. There are many more array functions in PHP than this book can cover. If you need to perform a complex array operation that you have not learned about, refer to the online documentation at www.php.net/ref.array. Sorting To sort the values in an array, you use the sort function or one of its derivatives, as in the following example: sort($temps); Sorting Functions sort and other related functions take a single array argument and sort that array. The sorted array is not returned; the return value indicates success or failure. Sorting the original $temps array with sort arranges the values into numeric order, but the key values are also renumbered. After you perform the sort, index 0 of the array will contain the lowest value from the array, and there is no way of telling which value corresponds to each month. You can use asort to sort an array while maintaining the key associations, whether it is an associative array or numerically indexed. After you sort $temps, index 0 will still contain January's average temperature, but if you loop through the array, the elements will be retrieved in sorted order. Using the associative array $temps as an example, the following code displays the months and their average temperatures, from coldest to hottest: $temps = array("jan" => 38, "feb" => 40, "mar" => 49, "apr" => 60, "may" => 70, "jun" => 79, "jul" => 84, "aug" => 83, "sep" => 76, "oct" => 65, "nov" => 54, "dec" => 42); asort($temps); foreach($temps as $month => $temp) { print "$month: $temp <br>\n"; } It is also possible to sort an array on the keys rather than on the element values, by using ksort. Using ksort on the associative $temps array arranges the elements alphabetically on the month name keys. Therefore, when you loop through the sorted array, the first value fetched would be $temps["apr"], followed by $temps["aug"], and so on. To reverse the sort order for any of these functions, you use rsort in place of sort. The reverse of asort is arsort, and the reverse of ksort is krsort. To reverse the order of an array as it stands without sorting, you simply use array_reverse. Randomizing an Array As well as sorting the values of an array into order, PHP provides functions so that you can easily randomize elements in an array. The shuffle function works in a similar way to the sorting functions: It takes a single array argument and shuffles the elements in that array into a random order. As with sort, the key associations are lost, and the shuffled values will always be indexed numerically. Set Functions By treating an array as a set of values, you can perform set arithmetic by using PHP's array functions. To combine the values from different arrays (a union operation), you use the array_merge function with two or more array arguments, as in the following example: $union = array_merge($array1, $array2, $array3, , ); A new array is returned that contains all the elements from the listed arrays. In this example, the $union array will contain all the elements in $array1, followed by all the elements in $array2, and so on. To remove duplicate values from any array, you use array_unique so that if two different index keys refer to the same value, only one will be kept. The array_intersect function performs an intersection on two arrays. The following example produces a new array, $intersect, that contains all the elements from $array1 that are also present in $array2: $intersect = array_intersect($array1, $array2); To find the difference between two sets, you can use the array_diff function. The following example returns the array $diff, which contains only elements from $array1 that are not present in $array2: $diff = array_diff($array1, $array2); Looking Inside Arrays The count function returns the number of elements in an array. It takes a single array argument. For example, the following statement shows that there are 12 values in the $temps array: echo count($temps); To find out whether a value exists within an array without having to write a loop to search through every value, you can use in_array or array_search. The first argument is the value to search for, and the second is the array to look inside: if (in_array("PHP", $languages)) { , } The difference between these functions is the return value. If the value exists within the array, array_search returns the corresponding key, whereas in_array returns only a Boolean result. Needle in a Haystack Somewhat confusingly, the order of the needle and haystack arguments to in_array and array_search is opposite that of string functions, such as strpos and strstr. To check whether a particular key exists in an array, you use array_key_exists. The following example determines whether the December value of $temps has been set: if (array_key_exists("dec", $temps)) { , } Serializing The serialize function creates a textual representation of the data an array holds. This is a powerful feature that gives you the ability to easily write the contents of a PHP array to a database or file. Lessons 17, "Filesystem Access," and 19, "Using a MySQL Database," deal with the specifics of filesystem and database storage. For now let's just take a look at how serialization of an array works. Calling serialize with an array argument returns a string that represents the keys and values in that array, in a structured format. You can then decode that string by using the unserialize function to return the original array. The serialized string that represents the associative array $temps is as follows: a:12:{s:3:"jan";i:38;s:3:"feb";i:40;s:3:"mar";i:49; s:3:"apr";i:60; s:3:"may";i:70;s:3:"jun"; i:79;s:3:"jul";i:84;s:3:"aug";i:83;s:3:"sep"; si:76;s:3:"oct";i:65;s:3:"nov";i:54;s:3:"dec";i:42;} You can probably figure out how this string is structured, and the only argument you would ever pass to unserialize is the result of a serialize operationthere is no point in trying to construct it yourself. Thank you, see u in the next class |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 4:00pm On Jun 23, 2009 |
Multidimensional Arrays It is possibleand often very usefulto use arrays to store two-dimensional or even multidimensional data. Accessing Two-Dimensional Data In fact, a two-dimensional array is an array of arrays. Suppose you were to use an array to store the average monthly temperature, by year, using two key dimensionsthe month and the year. You might display the average temperature from February 1995 as follows: echo $temps[1995]["feb"]; Because $temps is an array of arrays, $temps[1995] is an array of temperatures, indexed by month, and you can reference its elements by adding the key name in square brackets. Defining a Multidimensional Array Defining a multidimensional array is fairly straightforward, as long as you remember that what you are working with is actually an array that contains more arrays. You can initialize values by using references to the individual elements, as follows: $temps[1995]["feb"] = 41; You can also define multidimensional arrays by nesting the array function in the appropriate places. The following example defines the first few months for three years (the full array would clearly be much larger than this): $temps = array ( 1995 => array ("jan" => 36, "feb" => 42, "mar" => 51), 1996 => array ("jan" => 37, "feb" => 42, "mar" => 49), 1997 => array ("jan" => 34, "feb" => 40, "mar" => 50) ); The print_r function can follow as many dimensions as an array contains, and the formatted output will be indented to make each level of the hierarchy readable. The following is the output from the three-dimensional $temps array just defined: Array ( [1995] => Array ( [jan] => 36 [feb] => 42 [mar] => 51 ) [1996] => Array ( [jan] => 37 [feb] => 42 [mar] => 49 ) [1997] => Array ( [jan] => 34 [feb] => 40 [mar] => 50 ) ) |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 11:53pm On Jun 24, 2009 |
In previous lesson you have learned how to create arrays of data and manipulate them. This lesson examines how regular expressions are used to perform pattern matching on strings. Introducing Regular Expressions Using regular expressionssometimes known as regexis a powerful and concise way of writing a rule that identifies a particular string format. Because they can express quite complex rules in only a few characters, if you have not come across them before, regular expressions can look very confusing indeed. At its very simplest, a regular expression can be just a character string, where the expression matches any string that contains those characters in sequence. At a more advanced level, a regular expression can identify detailed patterns of characters within a string and break a string into components based on those patterns. Types of Regular Expression PHP supports two different types of regular expressions: the POSIX-extended syntaxwhich is examined in this lessonand the Perl-Compatible Regular Expression (PCRE). Both types perform the same function, using a different syntax, and there is really no need to know how to use both types. If you are already familiar with Perl, you may find it easier to use the PCRE functions than to learn the POSIX syntax. Documentation for PCRE can be found online at www.php.net/manual/en/ref.pcre.php. see u in d next class!!! |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 12:46am On Jun 25, 2009 |
Outstanding. . .keep it up bro, u are making us proud! |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 11:39am On Jul 02, 2009 |
IN CASE U NEVER KNOW PHP 5.3.0 Release Announcement The PHP development team is proud to announce the immediate release of PHP 5.3.0. This release is a major improvement in the 5.X series, which includes a large number of new features and bug fixes. The key features of PHP 5.3.0 include: Support for namespaces Late static binding Lambda Functions and Closures Syntax additions: NOWDOC, ternary short cut "?:" and jump label (limited goto), __callStatic() Under the hood performance improvements Optional garbage collection for cyclic references Optional mysqlnd PHP native replacement for libmysql Improved Windows support including VC9 and experimental X64 binaries as well as portability to other supported platforms More consistent float rounding Deprecation notices are now handled via E_DEPRECATED (part of E_ALL) instead of the E_STRICT error level Several enhancements to enable more flexiblity in php.ini (and ini parsing in general) New bundled extensions: ext/phar, ext/intl, ext/fileinfo, ext/sqlite3, ext/enchant Over 140 bug fixes and improvements to PHP, in particular to: ext/openssl, ext/spl and ext/date This release also drops several extensions and unifies the usage of internal APIs. Users should be aware of the following known backwards compatibility breaks: Parameter parsing API unification will cause some functions to behave more or less strict when it comes to type juggling Removed the following extensions: ext/mhash (see ext/hash), ext/msql, ext/pspell (see ext/enchant), ext/sybase (see ext/sybase_ct) Moved the following extensions to PECL: ext/ming, ext/fbsql, ext/ncurses, ext/fdf Removed zend.ze1_compatibility_mode visit the PHP website for more info. Class later |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 5:43pm On Jul 02, 2009 |
iight, we will get back to you then. . .lemme check it out |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by AsoRock5(m): 11:53pm On Jul 03, 2009 |
Hello Webmasters, I need your help guys! I need the feature forum link theme customization just like the one on nairaland homepage I'm running an SMF 1.1.9 version Thanks |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 8:24am On Jul 04, 2009 |
Maybe you should create the thread on the main board. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:55pm On Jul 22, 2009 |
Hello everyone what up? sori have been a bit busy. BRB |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by kesyboy(m): 9:00pm On Aug 22, 2009 |
Just give it a try |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 11:33am On Aug 23, 2009 |
brb. . .lol |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 11:27am On Aug 25, 2009 |
*dhtml:DHTML, u're suppose to be a brother, anyway am back. thanks for your patience |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 2:07pm On Aug 25, 2009 |
Using ereg The ereg function in PHP is used to test a string against a regular expression. Using a very simple regex, the following example checks whether $phrase contains the substring PHP: $phrase = "I love PHP"; if (ereg("PHP", $phrase)) { echo "The expression matches"; } If you run this script through your web browser, you will see that the expression does indeed match $phrase. Regular expressions are case-sensitive, so if the expression were in lowercase, this example would not find a match. To perform a non-case-sensitive regex comparison, you can use eregi: if (eregi("php", $phrase)) { echo "The expression matches"; } Performance The regular expressions you have seen so far perform basic string matching that can also be performed by the functions you learned about in d other Lesson, "Working with Strings," such as strstr. In general, a script will perform better if you use string functions in place of ereg for simple string comparisons. ok |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by fluxdon(m): 7:25pm On Aug 25, 2009 |
@quadrillio, u r really doing a great job. but i have a big challenge. am trying 2 make my search result have hyperlinks just like google search result. the search result of google come with the main header, little description and website. now the header and the website are both clickable. how is that achieved. take a look at this code. i am trying 2 make one of those fields(eventdescription) have a hyperlink when displaying on the page. <?php require_once(', /database_connection.php'); LoadDatabase(); SelectDatabase(); $query = 'SELECT `NameofEvent` , `VenueofEvent`, `State`, `EventDescription` , `EntryType`, `TicketPrice`, `NameofCompany` FROM `cat_birthday` LIMIT 0 , 30'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $count = 0; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td class='tabledata'>$col_value</td>\n"; } $count++; echo "\t</tr>\n"; } echo "</table>\n"; if ($count < 1) { echo "<br><br>No rows were found in this table.<br><br>"; } else { echo "<br><br><font face ='verdana' size = '1'>$count Events were found.</font><br><br>"; } ?> |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 1:54pm On Aug 26, 2009 |
to do something like that one canusually do it dis way: <html> <head><title> sample </sample></head> <body> <?php /* my connection, table selection, & my query come here */ ?> <a href= "details.php?id=<?php /*the path/page n d unique key */ ?>" > <?php /* select d column with d description */ ?> </a> </body> </html> I hope dis helps gurus in d house can add more, please safe |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 11:55am On Aug 29, 2009 |
Those codes are scatterin my head sef. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 1:20pm On Sep 01, 2009 |
*dhtml:LOL No codes jus explanation of where and how to place his codes. am trying to explain d solution SAFE |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by sanmathieu: 7:47pm On Sep 02, 2009 |
design ANY kind of website with me. alll you need do is contact me and we can talk about your plans and wht knd of website you want to design: contact me through any of this: sanmathieu@yahoo.com, onipeonimisi@gmail.com, and 07039148866, 08073853191, 08136436299. you can design any kind of website at a very cheap rate. we help you with the domain name and we help you load any kind of module you want. design websites like chat, blog, forum, community, etc. you dont need to worry yourself with scripting and all that because we use scripting languages like asp with access database or mysql or mssql, and we also use others like php/mysql, coldfusion (cfm) and other advanced website scripting and features. its easy, call me or you can text me. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 10:02am On Sep 04, 2009 |
Adverts! Adverts!! Adverts !!! Is this an advert board? |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Irem(m): 1:47pm On Sep 04, 2009 |
Yo quadrilo!! love your material men, ill love it if you post more PHP content to my email. westsideirem@gmail.com. please ill really apreciate it since ill be comencing some important website project ernest. |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 4:08pm On Sep 05, 2009 |
Irem:I ve sent you a link to download all d books u need on web Development, I hope it help and let me know if u have any problem be right to continue d tutorial SAFE |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by quadrillio(m): 4:23pm On Sep 05, 2009 |
sanmathieu: GUY MOVE. MOVE |
Re: Php Class For Beginners. Question Will Be Treated With High Priority. by Nobody: 4:34pm On Sep 05, 2009 |
Qad, I think that poster should be flogged! |
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (13) (Reply)
When You Are A Computer Guru And Your Girlfriend Needs Your Assistance / best BULK SMS provider in Nigeria ? / 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. 90 |