I have a function which basically retrieves the product id in a description.
private function scanForProductIdInDescription($string, $start, $end) {
$startpos = strpos($string, $start) + strlen($start);
if (strpos($string, $start) !== false) {
$endpos = strpos($string, $end, $startpos);
if (strpos($string, $end, $startpos) !== false) {
return substr($string, $startpos, $endpos - $startpos);
}
}
}
i use it as follows:
$from = "{PID =";
$end = "}";
$description = 'some text {PID =340} {PID =357}';
$product_id = $this->scanForProductIdInDescription($description, $from, $end);
at the moment, it only gets the first occurence in the string. I need to find all occurences in the string. The result should be: $product_id = 340,357;
thanks