Working with Text and
Numbers
Text
Numbers
Variables
TEXT
• Spend lot of time handling text
• Generates HTML and works with data in databases
• Slicing and dicing text means we can easily built the dynamic websites
• Pieces of text are called strings
• String can contain any characters( letters, numbers, spaces, tabs )
• String can even contain binary files such as image or sound
Defining text strings
• Simples way is to surround with single quotes(‘ ’)
• To print single quote inside single quote we need backslash
character()
• Also called as escape character
• Escape character can be escaped itself
• Only characters that get special treatment inside single quotes are
single quotes and backslash character
• Strings can also be defined with the help of double quotes but they
have more special characters
• String can also be defined with the help of here document
• To combine two strings period(.) is used
Manipulating Text
• Validation
• Input coming is as per our requirement or not
• Formating
• Change the look of the output
Validation
• trim()
• strlen()
• Comparing string with equality operator
• strcasecmp()
trim()
• Syntax:
• trim( string, charlist )
• Removes whitespaces and other pre-defined characters from left and
right of the string
• Related functions:
• ltrim( string, charlist )
• rtrim( string, charlist )
Formating
• strtoupper() - converts a string to uppercase
• strtolower() - converts a string to uppercase
• lcfirst() - converts the first character of a string to lowercase
• ucfirst() - converts the first character of a string to uppercase
• ucwords() - converts the first character of each word in a string to
uppercase
• The substr() function returns a part of a string.
• Syntax
• substr(string,start,length)
• A positive number - Start at a specified position in the string
• A negative number - Start at a specified position from the end of the
string
• 0 - Start at the first character in string
• The str_replace() function replaces some characters with some other
characters in a string.
• Syntax
• str_replace(find,replace,string)
Numbers
• Integers
• float
Arithmetic Operators
• *
• /
• %
• +
• -
Variables
• Holds the data in the program
Operating on variables
Combined assignment and addition
Combined assignment and concatenation
Incrementing and decrementing
Putting Variables inside string
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP

Text and Numbers (Data Types)in PHP