Archive for September, 2007

Web host 4 life - 144Part IPHP: The BasicsTable 8-1: Simple Inspection, Comparison,

Monday, September 10th, 2007

144Part IPHP: The BasicsTable 8-1: Simple Inspection, Comparison, and Searching FunctionsFunctionBehaviorstrlen()Takes a single string argument and returns its length as an integer. strpos()Takes two string arguments: a string to search, and the string being searchedfor. Returns the (0-based) position of the beginning of the first instance of thestring if found, and a false value otherwise. It also takes a third optionalinteger argument, specifying the position at which the search should begin. strrpos()Like strpos(), except that it searches backward from the end of the string, rather than forward from the beginning. The search string must only be onecharacter long, and there is no optional position argument. strcmp()Takes two strings as arguments and returns 0 if the strings are exactlyequivalent. If strcmp()encounters a difference, it returns a negativenumber if the first different byte is a smaller ASCII value in the first string, anda positive number if the smaller byte is found in the second string. strcasecmp()Identical to strcmp(), except that lowercase and uppercase versions of thesame letter compare as equal. strstr()Searches its first string argument to see if its second string argument iscontained in it. Returns the substring of the first string that starts with the firstinstance of the second argument, if any is found otherwise, it returns false. strchr()Identical to strstr(). stristr()Identical to strstr()except that the comparison is case independent. Substring selectionMany of PHP s string functions have to do with slicing and dicing your strings. By slicing,wemean choosing a portion of a string; by dicing,we mean selectively modifying a string. Keepin mind that (most of the time) even dicing functions do not change the string you started outwith. Usually, such functions return a modified copy, leaving the original argument intact. The most basic way to choose a portion of a string is the substr()function, which returns anew string that is a subsequence of the old one. As arguments, it takes a string (that the sub- string will be selected from), an integer (the position at which the desired substring starts), and an optional third integer argument that is the length of the desired substring. If no thirdargument is given, the substring is assumed to continue until the end. (Remember that, aswith all PHP arguments that deal with numerical string positions, the numbering starts with 0rather than 1.) For example, the statement: echo(substr( Take what you need, and leave the rest behind , 23)); prints the string leavetherestbehind, whereas the statement: echo(substr( Take what you need, and leave the rest behind , 5, 13)); prints whatyouneed a 13-character string starting at (0-based) position 5.10
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

143Chapter 8StringsComparison and searchingIs this string the (Cedant web hosting) same

Sunday, September 9th, 2007

143Chapter 8StringsComparison and searchingIs this string the same as that string? It s a question that your code is likely to have to answerfrequently, especially when dealing with input typed by the end user. For the ==operator, two strings are the same if they contain exactly the same sequence ofcharacters. It does not test any stricter notion of being the same, such as being stored at thesame memory address, but it does pay attention to case (or capitalization). The simplest method to find an answer is to use the basic comparison operator (==), whichdoes equality testing on strings as well as numbers. Comparing two strings using ==(or the corresponding operators) is trustworthy ifboth the arguments are strings and if you know that no type conversion is being performed. (See Chapter 5 for more on this.) Using strcmp()(described next) is always trustworthy. The most basic workhorse string-comparison function is strcmp(). It takes two strings asarguments and compares them byte by byte until it finds a difference. It returns a negativenumber if the first string is less than the second and a positive number if the second string isless. It returns 0if they are identical. The strcasecmp()function works the same way, except that the equality comparison is caseinsensitive. The function call strcasecmp( hey! , HEY! )should return 0. SearchingThe comparison functions just described tell you whether one string is equal to another. Tofind out if one string is contained within another, use the strpos()function (covered earlier) or the strstr()function (or one of its relatives). The strstr()function takes a string to search in and a string to look for (in that order). If itsucceeds, it returns the portion of the string that starts with (and includes) the first instanceof the string it is looking for. If the string is not found, a false value is returned. Here is a suc- cessful search followed by an unsuccessful search: $string_to_search = showsuponceshowsuptwice ; $string_to_find = up ; print( Result of looking for $string_to_find . strstr($string_to_search, $string_to_find) .
); $string_to_find = down ; print( Result of looking for $string_to_find . strstr($string_to_search, $string_to_find)); which gives us: Result of looking for up: uponceshowsuptwiceResult of looking for down: The blank space after the colon in the second line is the result of trying to print a false value, which prints as the empty string. The strstr()function also has an alias by the name ofstrchr(). Other than the name, the two functions are identical. Just as with strcmp(), strstr()has a case-insensitive version, by the name of stristr(). (That iin the middlestands for insensitive.) It is identical to strstr()in every way, except that the comparisontreats lowercase letters as indistinguishable from their uppercase counterparts. The stringfunctions we have covered so far are summarized in Table 8-1. CautionNote10
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

142Part IPHP: The BasicsThe strpos()function is one of (Web server setup)

Sunday, September 9th, 2007

142Part IPHP: The BasicsThe strpos()function is one of those cases where PHP s type-looseness can be problematic. If no match can be found, the function returns a false value; if the very first character is a match, the function returns 0(because the indexing count starts with 0 rather than 1). Both of thesevalues look false if used in a Boolean test. One way to distinguish them is to use the identitycomparison operator (===, introduced as of PHP4), which is true only if its arguments are thesame and of the same type you can use it to test if the returned value is 0(or is FALSE) with- out risk of confusion with other values that might be the same after type coercion. If you areusing PHP3, you need to do explicit type testing with, for example, is_integer(). The strpos()function can also be used to search for a substring rather than a single charac- ter, simply by giving it a multicharacter string rather than a single-character string. You canalso supply an extra integer argument specifying the position to begin searching forward from. Searching in reverse is also possible, using the strrpos()function. (Note the extra r, whichyou can think of as standing for reverse.) This function takes a string to search and a single- character string to locate, and it returns the last position of occurrence of the second argu- ment in the first argument. (Unlike with strpos(), the string searched for must have onlyone character.) If we use this function on our example sentence, we find a different position: $twister = Peter Piper picked a peck of pickled peppers ; printf( Location of p is . strrpos($twister, p ) .
); Specifically, we find the third pin peppers: Location of p is 40CautionAre strings immutable? In some programming languages (such as C), it is common to manipulate strings by directlychanging them that is, storing new characters into the middle of an existing string, replacingold characters. Other languages (like Java) try to keep the programmer out of certain kinds oftrouble by making string classes that are immutable(or unchangeable) you can make newstrings by creating modified copies of old ones, but once you have made a string, you are notallowed to change it by directly changing the characters that make it up. Where does PHP fit in? As it turns out, PHP strings can be changed, but the most common practice seems to be to treat strings as immutable. Strings can be changed by treating them as character arrays and assigning directly into them, likethis: $my_string = abcdefg ; $my_string[5] = X ; print($my_string .
); which will give the browser output: abcdeXgThis modification method seems to be undocumented, however, and shows up nowhere in theonline manual, even though the corresponding extraction method (now updated to use curlybraces) is highlighted. Also, almost all PHP string-manipulation functions return modified copiesof their string arguments rather than making direct changes, which seems to indicate that this isthe style that the PHP designers prefer. Our advice is not to use this direct-modification methodto change strings, unless you know what you are doing and there is some large benefit in termsof memory savings.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

141Chapter 8StringsIn this section, we present the basic (Web design course)

Saturday, September 8th, 2007

141Chapter 8StringsIn this section, we present the basic functions for inspecting, comparing, modifying, andprinting strings. If you want to be really comfortable with string manipulation in PHP, youshould probably have at least a passing acquaintance with everything in this section. Boththe regular expression functions and the more abstruse string functions can be found inChapter 22. A note for C programmers: Many of the PHP string function names should be familiar to you. Just keep in mind that, because PHP takes care of memory management for you, the func- tions that return strings are allocating the string storage on their own and do not need to begiven a preallocated string to write into. Inspecting stringsWhat kinds of questions can you ask strings? First on the list is how long the string is, usingthe strlen()function (the name is short for string length). $short_string = This string has 29 characters ; print( It does have . strlen($short_string) . characters ); This code gives the following output: It does have 29 charactersKnowing the string s length is particularly useful in form validation or for situations in whichwe d like to loop through a string character by character. A useless but illustrative example, using the preceding example string, is: for ($index = 0; $index < strlen($short_string); $index++) print($short_string{$index}); This simply prints: This string has 29 characterswhich is the string we started with. Finding characters and substringsThe next question you can ask your strings is what they contain. For example, the strpos() function finds the numerical position of a particular character in a string, if it exists. $twister = Peter Piper picked a peck of pickled peppers ; print( Location of p is . strpos($twister, p ) .
); print( Location of q is . strpos($twister, q ) .
); This gives us the browser output: Location of p is 8Location of q isThe q location is apparently blank because strpos()returns false if the character in ques- tion cannot be found, and a false value prints as the empty string. You should note that thestrpos()function is case-sensitive. Note10
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

140Part IPHP: The BasicsNote that, unlike commutative addition (Make web site)

Friday, September 7th, 2007

140Part IPHP: The BasicsNote that, unlike commutative addition and multiplication, with this shorthand operator itmatters that the new string is added to the right. If you want the new string tacked on to theleft, there s no alternative shorter than: $my_string_var = $new_addition . $my_string_var; Note also that unassigned variables are treated as empty strings for the purposes of concate- nation, so $my_string_varwill end up unchanged if $new_additionhas never been given avalue. The heredoc syntaxIn addition to the single-quote and double-quote syntaxes, PHP offers another way to specifya string, called the heredoc syntax. This syntax turns out to be extremely useful for specifyinglarge chunks of variable-interpolated text, because it spares you from the need to escapeinternal quotes. It is especially useful in creating pages that contain HTML forms. The operator in the heredoc syntax is <<<. What is expected immediately after this is a label(unquoted) that indicates the beginning of a multiline string. PHP will continue including sub- sequent lines into this string until it sees the same label again, beginning a line. The endinglabel may optionally be followed by a semicolon but by nothing else. An example: $my_string_var = << ENDOFFORM; This has the effect of echoing a very simple form to the browser. String FunctionsPHP gives you a huge variety of functions for the munching and crunching of strings. If you reever tempted to roll your own function that reads strings character-by-character to produce anew string, pause for a moment to think whether the task might be common. If so, there isprobably a built-in function that handles it.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

139Chapter 8StringsYou can retrieve the individual characters of (Windows 2003 server web)

Thursday, September 6th, 2007

139Chapter 8StringsYou can retrieve the individual characters of a string by including the number of the charac- ter, starting at 0, enclosed in curly braces immediately following a string variable. These characters will actually be one-character strings. For example, the following code: $my_string = Doubled ; for ($index = 0; $index < 7; $index++) { $string_to_print = $my_string{$index}; print( $string_to_print$string_to_print ); } gives the browser output: DDoouubblleeddwith each character of the string being printed twice per loop. (The number 7 is hard-codedin this example only because we haven t yet covered how to find out the length of a string see the function strlen()in the later section Inspecting strings. ) In earlier versions of PHP, it was customary to retrieve individual characters of a string usingsquare brackets to enclose the index rather than curly braces (for example, $my_string[3] rather than $my_string{3}). While you can still use the square (array-like) brackets to dothis, this usage is now deprecated, and the curly brace syntax is encouraged. String operatorsPHP offers only one real operator on strings: the dot (.) or concatenation operator. Thisoperator, when placed between two string arguments, produces a new string that is the resultof putting the two strings together in sequence. For example: $my_two_cents = I want to give you a piece of my mind ; $third_cent = And another thing ; print($my_two_cents . ... . $third_cent); gives the browser output: I want to give you a piece of my mind ... And another thingNote that we are not passing multiple string arguments to the print statement we are hand- ing it one string argument, which was created by concatenating three strings together. Thefirst and third strings are variables, but the middle one is a literal string enclosed in doublequotes. Note that the concatenation operator is not +as in Java, and it does not overload anythingelse. If you forget this and add strings using +, they will be interpreted as numbers, with theresult that one + two equals 0(because no successful string-to-number conversion canbe made). Concatenation and assignmentJust as with arithmetic operators, PHP has a shorthand operator (.=) that combines concate- nation with assignment. The following statement: $my_string_var .= $new_addition; is exactly equivalent to: $my_string_var = $my_string_var . $new_addition; NoteCaution10
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

138Part IPHP: The BasicsFor the details on exactly (Web server info)

Thursday, September 6th, 2007

138Part IPHP: The BasicsFor the details on exactly how PHP interprets both singly and doubly quoted strings, see the Strings section of Chapter 5. Interpolation with curly bracesIn most situations, you can simply include a variable in a doubly quoted string, and the vari- able s value will be spliced into the string when it is interpreted. There are two situationswhere the string parser might very reasonably get confused and need more guidance fromyou. The first situation is when your notion of where the variable name should stop is not thesame as the parser s, and the other occurs when the expression you want to have interpo- lated is not a simple variable. In these cases, you can clear things up by enclosing the valueyou want interpolated in curly braces: {}. For example, PHP has no difficulty with the following code: $sport = volleyball ; $plan = I will play $sport in the summertime ; The parser in this case encounters the $symbol, and then begins collecting characters for avariable name until it runs into the space after $sport. Spaces cannot be part of a variablename, so it is clear that the variable in question is $sport, and PHP successfully finds a valuefor that variable ( volleyball ), and splices the value in. Sometimes, though, it is not convenient to stop a variable name with a space. Take this example. $sport1 = volley ; $sport2 = foot ; $sport3 = basket ; $plan1 = I will play $sport1ball in the summertime ; //wrong$plan2 = I will play $sport2ball in the fall ; //wrong$plan3 = I will play $sport3ball in the winter ; //wrongYou will not get the desired effect here, because PHP interprets $sport1as part of the vari- able name $sport1ball, which is probably unbound. Instead, you need something like: $plan1 = I will play {$sport1}ball in the summertime ; //rightwhich asks PHP to evaluate only the variable expression within the braces before interpolating. For similar reasons, PHP has difficulty interpolating complex variable expressions, like multidi- mensional arrays and object variables, unless curly braces are used. The general rule is that ifyou have a {immediately followed by a $, PHP will evaluate the variable expression up until the closing }and will interpolate the resulting value into the string. (If you need a literal {$toappear in your string, you can accomplish it by escaping either character with a backslash ()). See the Concatenation and Assignment section later in this chapter for ideas on other waysto address challenges like this. Characters and string indexesUnlike some programming languages, PHP has no distinct character type different from thestring type. In general, functions that would take character arguments in other languagesexpect strings of length 1 in PHP. TipCross- Reference10
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Web site builder - StringsAlthough images, sound files, videos, animations, and appletsmake

Wednesday, September 5th, 2007

StringsAlthough images, sound files, videos, animations, and appletsmake up an important portion of the World Wide Web, much ofthe Web is still text one character s worth after another, like thissentence. The basic PHP datatype for representing text is the string. In this chapter, we cover almost all PHP s capabilities for manipulat- ing strings (although we leave more advanced string functions andthe pattern-matching power of regular expressions for separate treat- ment in Chapter 22). We start with the basics of strings, move to themost commonly used operators and functions, and demonstratethem by continuing the exercise calculator example from Chapter 7. Strings in PHPStrings are sequences of characters that can be treated as a unit assigned to variables, given as input to functions, returned from func- tions, or sent as output to appear on your user s Web page. The sim- plest way to specify a string in PHP code is to enclose it in quotes, whether single quotes ( ) or double quotes ( ), like this: $my_string = A literal string ; $another_string = Another string ; The difference between single and double quotes lies in how muchinterpretation PHP does of the characters between the quote signsbefore creating the string itself. If you enclose a string in singlequotes, almost no interpretation will be performed; if you enclose itin double quotes, PHP will splice in the values of any variables youinclude, as well as make substitutions for certain special charactersequences that begin with the backslash () character. For example, if you evaluate the following code in the middle of a Web page: $statement = everything I say ; $question_1 = Do you have to take $statement so literally?n
; $question_2 = Do you have to take $statement so literally?n
; echo $question_1; echo $question_2; you should expect to see the browser output: Do you have to take everything I say so literally? Do you have to take $statement so literally?n88CHAPTER …In This ChapterStrings in PHPString functionsExtended example: calculator …
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

136Part IPHP: The BasicsListing 7-4(continued) But before we (Zeus web server)

Tuesday, September 4th, 2007

136Part IPHP: The BasicsListing 7-4(continued) But before we can do anything interesting with it, we need to learn about strings.

Figure 7-4 represents the output of wc_handler_var.phpon success. Figure 7-4:Data successfully passed from one page to anotherIn Chapter 8, we will learn to take this string input and do interesting things with it. SummaryThe HTTP protocol is stateless. This means a plain HTML page is incapable of receiving infor- mation from any other page. It can be used to pass values via a URL or an HTML form, but aseparate program called a form handlermust step in to recognize and perform actions on thepassed values. In first-generation Web development, these form handlers were Perl or C CGIscripts, but nowadays Web developers are more likely to use an HTML-embedded program- ming language like PHP. PHP makes it particularly easy to write form handlers and even tocombine them with HTML display on a single Web page. Information is passed between Web pages using one of four main methods: GET, POST, a cookie, or sessions. GETis mainly used to construct complex URL strings for use with dynamically gen- erated pages. It is deprecated for use with most HTML forms. POSTis the method recommendedfor most forms. Forms are the main way to pass information from one Web page to a single otherWeb page. We deal with the persistent state methods, cookies, and sessions in Chapter 24. …
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

My space web page - 135Chapter 7Passing Information between PagesFigure 7-3:A simple form

Monday, September 3rd, 2007

135Chapter 7Passing Information between PagesFigure 7-3:A simple form passing a string variableThe matching form handler is called wc_handler_var.php (Listing 7-4). Listing 7-4:Form handler (wc_handler_var.php)

Workout calculator handler, part 1

We ve successfully passed the contents of thetext input field,
as a variable called exercise with a value of.
Continued09
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.