To access a character at a particular position, or index , within a string, use:
$character = $string[index];
You place the index between square brackets after the string variable name.
String indices start from 0, so the first character in the string has an index of 0.
The second has an index of 1, and so on.
You can both read and change characters this way.
Here are some examples:
<?php $myString = "Hello, world!"; echo $myString . " \n "; echo $myString . " \n "; $myString ='?'; echo $myString . " \n "; ?>// w ww. jav a 2 s . c om