Changes

Jump to: navigation, search

Understanding PHP Variable Types

711 bytes added, 20:18, 25 May 2007
Extracting and Writing String Fragments
== Extracting and Writing String Fragments ==
Once we have defined a string variable we can extarct or make changes to individual characters in the string using what is termed {x} notation, where ''x'' represents the index into the string of the character we wish to view or change. Before we look at an example it is important to keep in mind that the index into the string is zero based. By this we mean that the first character of thsi string is in position 0, not position 1. For example to change the first and last characters of a string variable:
<pre>
<?php
 
$myString = "My Bug";
 
$myString{0} = "m";
$myString(5] = "s";
 
echo $myString;
?>
</pre>
 
The result of the above script will change the string from:
 
<tt>My Bug</tt>
 
to:
 
<tt>my Bus</tt>
== Creating PHP heredoc Strings ==

Navigation menu