Changes

Jump to: navigation, search

Working with Strings and Text in PHP

786 bytes added, 14:54, 4 June 2007
Converting a String into a PHP Array
Array ( [0] => This [1] => is [2] => a [3] => short [4] => string )
</pre>
 
== Removing Leading and Trailing Whitescape from a PHP String ==
 
The leading and trailing whitespcae can be removed from a string using the PHP ''trim()'' function. Whitespace characters are defined by PHp to be space, tab, newline, carriage return, NULL and vertical tab characters.
 
The ''trim()'' command takes the string to be trimmed as an argument and returns a modified version of the string. The function is non-destructive, in that it does not modify the original string.
 
The following exmaple trims the whitespace from the specified string:
 
<pre>
<?php
$string = " This is a string with lots of whitespace ";
 
echo "Before trim [$string]";
 
$trimmedString = trim($string);
 
echo "After trim [$trimmedString]";
 
?>
 
</pre>
 
== Comparing String in PHP ==

Navigation menu