I am trying to do the following in PHP and would greatly appreciate any and all help.
- store the location of each instance of a character in a string in an array
- use a for loop to navigate the array and replace the character at each position, each element in the array, with another character.
Here is what I have so far:
$character1="/";
$character2="%";
$string1="hello / how / are / you / doing";
$characterPositions = array();
/* store locations of $character1 in $string1 */
foreach($characterPositions as $position){
/* replace what is at each $position in string $string1 */
}
I know str_replace would do just this, but I want to learn how to do this the above mentioned way.