Page 146 - Open Soource Technologies 304.indd
P. 146
Unit 8: Working with Strings, Date and Time
The strings starts with <<<, followed by a string that you know doesn’t appear in your text. Notes
It is terminated by writing that string at the beginning of a line, followed by an optional
semicolon (;), and then a required newline (\n).
Escaping and variable substitution in here-docs is identical to double-quoted strings except that
you are not required to escape double quotes.
8.6 PHP String Handling Functions
PHP is equally powerful than any other server side scripting languages in handling strings.
We will experiment with some of the string functions of PHP with some examples. There are
powerful functions like regular expressions to manage complex string handling requirements.
Here are some of them.
Function Action
chr Returns the character corresponding to an ASCII
code.
crypt One way encoding of a string (called hashing).
explode Converts a character delimited string into an
arraylike the VB Split function.
implode Converts an array into a character delimited string.
ltrim Remove characters (default is remove blanks) from
the beginning of a string.
ord Return the ASCII code of a character.
parse_str Extract the variables from a query string passed
via a URL.
print Display a string. Always return 1.
printf Display a formatted string. Returns the length of
the formatted string.
rtrim Remove characters (default is remove blanks) from
the endof a string.
sprintf Return a formatted string.
str_replacestr_ireplace Replace all occurrences of a substring within a
string.&nsp;
str_split Split a string into an array equal length chunks
(defaultlength 1).
strcmp Binary-safe string comparison.
strlen Returns the length of a string.
strposstripos Returns the position of first occurrence of a
substringin a string.
strrev Returns a string with characters reversed.
strtolower Returns a string with all characters converted to
lowercase.
Contd...
LOVELY PROFESSIONAL UNIVERSITY 141