I thought this would work but it appears to be only removing the - and the whitespace after it.
$itemList[] = preg_replace('/-(.*?)/i', "", $temp['item']);
I thought this would work but it appears to be only removing the - and the whitespace after it.
$itemList[] = preg_replace('/-(.*?)/i', "", $temp['item']);
Try:
$itemList[] = preg_replace('/-(.*)$/i', "", $temp['item']);
The $ symbol matches the end of the input, so forces the .* to grab to the end.
Adding a ? after the * makes it un-greedy, meaning it will grab the minimum possible, not the maximum possible, so in this case it is exactly what you don't want.
Why were you using non-greedy *?
?
$itemList[] = preg_replace('/-.*/i', "", $temp['item']);
Also, the capturing parens were unnecessary.