Generate array with substrings positions

0

Is there any way I can get a string, for example: "John was bar last night". Generate an array that stores the position of all "" strings of this string.

I'll use this to put these positions, for example, "no", "de". Having thus: "John went to the bar last night."

    
asked by anonymous 21.11.2018 / 20:16

1 answer

1

Why do not you use explode () in the string and transforms every sentence into an array? Then go back to the string with the new text?

<?php
// Example 1
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

Explode handbook link

    
21.11.2018 / 20:32