Changes

Jump to: navigation, search

Working with Strings and Text in PHP

452 bytes added, 16:23, 4 June 2007
Accessing and Modifiying Characters in String
$myString = "abcdefghijklmn";
$myChar = $myString{1};
echo "2nd Char = $myChar";
?>
</pre>
 
The above example will result in the following output:
 
<tt>2nd Char = b</tt>
 
Similarly the character postion can be assigned a new value suing the assigment operator:
 
<pre>
<?php
$myString = "abcdefghijklmn";
 
echo "Before change = $myString";
 
$myString{1} = 'B';
 
echo "Before change = $myString";
?>
</pre>
 
The result from the above output will read as follows:
 
<tt>Before change = abcdefghijklmn</tt>
<tt>Before change = aBcdefghijklmn</tt>

Navigation menu