You are almost there :).
From what I can gather, you want the first part of the title to be displayed separately from the rest of the title. I have used the hyphen character ('-') as the delimiter instead of ' - ' with spaces between the hyphen. I also use the 'trim()' function to remove any leading or trailing spaces from the second line '$line2' -
function split_product_title($title)
{
$hyphen_pos = strpos($title, ' - ');
if ($hyphen_pos !== false) {
$line1 = substr($title, 0, $hyphen_pos);
$line2 = substr($title, $hyphen_pos + 3);
$line2 = preg_replace('/[^\w\s]/u', '', $line2);
return $line1 . " <br> " . $line2;
}
return $title;
}
Make a call to your function -
$product_title = '0101-12-12 – 3/4" MNPT X 3/4" MNPT STR';
$split_title = split_product_title($product_title);
echo $split_title;
Output is -
0101-12-12
3/4" MNPT X 3/4" MNPT STR
EDIT/UPDATE]
The above code works well with normal hyphens. As it turned out, the OP had 'emdash-es' in his input which did not get replaced. To remove the 'emdash' symbols, use the following -
$title = '0101-12-12 – 3/4" MNPT X 3/4" MNPT STR';
$title = str_replace(["–"], '', $title);
echo $title;