[ Pobierz całość w formacie PDF ]
.In this hour, you have covered some of thefunctions that enable you to take control of the strings in your scripts.You learned how to format strings with printf() and sprint().You should be able touse these functions both to create strings that transform data and lay it out.Youlearned about functions that investigate strings.You should be able to discover thelength of a string with strlen(), determine the presence of a substring with strpos(),or extract a substring with substr().You should be able to tokenize a string withstrtok().Finally, you learned about functions that transform strings.You can now removewhite space from the beginning or end of a string with trim(), ltrim(), or chop().Youcan change case with strtoupper(), strtolower(), or ucwords().You can replace allinstances of a string with str_replace(). 332Believe it or not, you are not finished with strings yet.PHP supports regularexpressions that are an even more powerful means of working with strings than thefunctions already examined.Regular expressions are the subject of the next hour.Q&AQ Are there any other string functions that might be useful to me?A Yes.PHP4 has about 60 string functions! You can read about them all in the PHP4online manual at http://www.php.net/manual/ref.strings.php.Q In the example that demonstrated printf(), we showed the formatting bywrapping our output in tags.Is this the best way of showingformatted plain text on a browser?A tags can be useful if you want to preserve plain text formatting in an HTMLcontext.If you want to output an entire text document to the browser, however, itis neater to tell the browser to format the entire output as plain text.You can do thiswith the header() function:WorkshopThe Workshop provides quiz questions to help you solidify your understanding of thematerial covered.Try to understand the quiz answers before continuing to the nexthour's lesson.Quiz answers are provided in Appendix A.QuizWhat conversion specifier would you use with printf() to format an integer as adouble? Write down the full syntax required to convert the integer 33.How would you pad the conversion you effected in question 1 with zeroes so thatthe part before the decimal point is four characters long?How would you specify a precision of two decimal places for the floating-pointnumber we have been formatting in the previous questions?What function would you use to determine the length of a string?What function would you use to acquire the starting index of a substring withina string?What function would you use to extract a substring from a string?How might you remove white space from the beginning of a string?How would you convert a string to uppercase characters?How would you break up a delimited string into an array of substrings? 333ActivitiesCreate a feedback form that accepts a user's full name and an email address.Use case conversion functions to capitalize the first letter of each name the usersubmits and print the result back to the browser.Check that the user's emailaddress contains the @ symbol and print a warning otherwise.Create an array of doubles and integers.Loop through the array converting eachelement to a floating-point number with a precision of 2.Right-align the outputwithin a field of 20 characters. 334Hour 18: Working with RegularExpressionsOverviewRegular expressions are a powerful way of examining and modifying text.Theyenable you to search for patterns within a string, extracting matches flexibly andprecisely.Be warned that because they are more powerful, they are also slowerthan the more basic string function examined in Hour 17, "Working with Strings."You should use string functions, therefore, if you don't need the extra powerafforded by the use of a regular expression function.PHP supports two flavors of regular expression.It has a set of functions thatemulate regular expressions as employed in Perl, and a set of function that supportthe more limited POSIX regular expressions.You will examine both.In this hour, you will learnHow to match patterns in strings using regular expressionsThe basics of regular expression syntaxHow to replace text in strings using regular expressionsHow to work with powerful Perl compatible regular expressions to match andreplace patterns in textPOSIX Regular Expression FunctionsPOSIX regular expression functions make it possible for you to match and replacecomplex patterns in strings [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • szamanka888.keep.pl