Changes

Working with Strings and Text in PHP

492 bytes added, 16:19, 4 June 2007
Accessing and Modifiying Characters in String
== Accessing and Modifiying Characters in String ==
 
The individual characters in a string can be accessed and modified by their position in a string. To achieve this, simply place the position of the required character in braces {} after the string variable name. Keep in mind that indexes are zero based, so the first character in a string in index position 0, ''not'' position 1.
 
For example to access the 2nd character in a string:
 
<pre>
<?php
 
$myString = "abcdefghijklmn";
 
$myChar = myString{1};
 
echo "2nd Char = $myChar";
 
?>
</pre>