I have a php function which selects the text from a string between 2 different character sequences.
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
$fullstring = ',""Word1, Word2""';
$parsed = get_string_between($fullstring, ',""', '""');
echo $parsed; //Result = Word1, Word2
However, I would like to extend this further to select all matches when there are multiple occurrences within the string (this is likely, since the string will be generated by a csv file with hundreds of lines and hundreds of matches.) For example:
$fullstring = ',""Word1, Word2"" and another thing ,""Word3, Word4""';
And within each substring I will need to remove certain characters. In this example, I need to remove commas.
Can anybody suggest the most straightforward way of achieving this? Thanks.