I previously had some help with this matter from @HSZ but have had trouble getting the solution to work with an existing array. What im trying to do is explode quotes, make all words uppercase plus get each words index value and only echo the ones i define then implode. In simplest terms, always remove the 4th word within quotations or the 3rd and 4th… This could probably done with regex as well.
Example:
Hello [1] => World [2] => This [3] => Is [4] => a [5] => Test ) 6 only outputs the numbers i define, such as 1 – (Hello) and [2] – (World) leaving out [3], [4], [5] and [6] or This is a test leaving only Hello World, or 1 and [6] for Hello Test…
Such as:
echo $data[1] + ' ' + $data[6]; //Would output index 1 and 6 Hello and Test
Existing Code
if (stripos($data, 'test') !== false) {
$arr = explode('"', $data);
for ($i = 1; $i < count($arr); $i += 2) {
$arr[$i] = strtoupper($arr[$i]);
$arr[$i] = str_word_count($arr, 1); // Doesnt work with array of course.
}
$arr = $matches[1] + ' ' + $matches[6];
$data = implode('"', $arr);
}
Assuming
$datais'Hello world "this is a test"',$arr = explode('"', $data)will be the same as:If you want to do things with
this is a test, you can explode it out using something like$testarr = explode(' ', $arr[1]);.You can then do something like: