Creating PHP Pages - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Creating PHP Pages

Description:

Creating PHP Pages Chapter 9 PHP Strings PHP Strings A string can be single-quoted or double-quoted. Or in heredoc syntax (creates a large text string without needing ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 12
Provided by: Rizki76
Category:
Tags: php | creating | pages

less

Transcript and Presenter's Notes

Title: Creating PHP Pages


1
Creating PHP Pages
  • Chapter 9
  • PHP Strings

2
PHP Strings
  • A string can be single-quoted or double-quoted.
  • Or in heredoc syntax (creates a large text string
    without needing quotes, and can be used anyplace
    a string would go)
  • ltltltDONE
  • your_string_here
  • DONE
  • The string concatenation operator, .
  • Several functions for string are available
  • Manipulation with a regular expression,
  • Conversion between a string and an array,
  • Outputing by echo(), print(), printf(), and
    print_r(), and
  • Others

3
Single-Quoted String
  • No evaluation occurs for a single-quoted string.
  • age 20
  • echo I am name.\n
  • echo Single
  • echo \Double\
  • echo Double
  • echo age gt 18 ? OK
  • Output
  • I am age.\n
  • (illegal operation)
  • \Double\
  • Double
  • OK

4
Double-Quoted String
  • Variables and escape sequences within a
    double-quoted string are evaluated or replaced.
  • age 20
  • echo I am name.\n
  • echo Single\n
  • echo \Double\\n
  • echo Double
  • echo age gt 18 ? OK
  • Output
  • I am 20.
  • single
  • Double
  • (illegal operation)
  • OK

5
String
  • int strlen(string) returns the length of string.
  • str Name'
  • len strlen(str)
  • echo len
  • Output
  • 4

6
String
  • int strpos(string1, string2) returns the numeric
    position of string2 in string1.
  • str My house.'
  • position strpos(str, house)
  • echo position
  • Output
  • 4

7
String
  • int strpos(str1, str2 )
  • Returns FALSE if str2 is not a substring of
    str1.
  • Returns 0 if str2 is at the beginning of str1,
    so using (strpos(str1, str2) 0) could cause
    an unreliable result.
  • if(strpos(str1, str2) 0) may be used.

8
Substring
  • Returns the string present in string starting
    from location start until end of string.
  • Basic syntax
  • string substr(string, start)
  • Example
  • str My dog.
  • str2 substr(str, 3)
  • echo str2
  • str3 substr(str1, 3, 2)
  • echo str3
  • Output
  • dog.
  • do

9
String
  • array explode(delim, string) creates an array of
    the substrings in string, separated by delimiter.
  • Example
  • str My Sweet Home
  • arr explode(" ", str)
  • echo arr0\narr1\narr2\n
  • Output
  • My
  • Sweet
  • Home

10
String
  • string implode(delim, array)creates a string out
    of the elements in array, connected by delimiter.
  • Example
  • arr array(One', Two, Three)
  • string implode(', arr)
  • echo string
  • Output
  • OneTwoThree
  • There still many more example, you can learn it
    in php website.

11
References
  • References
  • Anonymous.(n.d.). Apache HTTP Server
    Documentation Version 2.2. Retrieved from
    http//httpd.apache.org/docs/2.2/.
  • Achour, M., Betz, F. (n.d.), PHP Manual.
    Retrieved from http//www.php.net/download-docs.ph
    p.
  • Anonymous. (n.d.). MySQL Reference Manual.
    Retrieved from http//downloads.mysql.com/docs/.
  • Naramore, E., Gerner, J., Le Scouarnec, Y.,
    Stolz, J., Glass, M. K. (2005). Beginning PHP5,
    Apache, and MySQL Web Development. Indianapolis,
    IN Wiley Publishing, Inc.
Write a Comment
User Comments (0)
About PowerShow.com