34,333
edits
Changes
→Finding the Length of a PHP String
?>
</pre>
== Converting a String into a PHP Array ==
Any string in PHP can be converted into a PHP array (see the [[PHP Arrays]] for an overview of arrays). This is achived the the PHP ''explode()'' function. The ''explode()'' function takes three arguments and returns an array:
* '''delimeter''' - the character that is to be used as the break point between array elements. For example a space character or a comma.
* '''string''' - the string that is to be converted into an array.
* '''divisions''' - (Optional). Sepcified the maximim number of array elements the string should be broken up into. When the limit is reach the final array element contains the remainder of the string.
The following example shows the ''explode()'' function in use:
<pre>
<?php
$myString = "This is a short string";
$myArray = explode($myString);
print_r($myArray);
?>
</pre>
The above example will result in the following output, which shows each word in the sentance assigned to an array element:
<pre>
Array ( [0] => This [1] => is [2] => a [3] => short [4] => string )
</pre>