Preg_replace替换特定短语

I have a description that has two pieces of text I'd like removed and the text to be formatted. The string can change and have both   and whitespace in it (it's bad data).

I need to remove both the product name and a block of text at the end (both of which can change per "product"). I've got the product name stored as a variable like so:

$prName = "Test CPL560 Home Office Corner Workstation";

And the text from the end that needs removed is as follows:

free delivery5-7 working days  assembly required?Yes   guarantee2 years  dimensions(mm) Width:  1600-2340  Depth:  700-1350  Height: 760

Removing the product name should be fairly straightforward but the last block of text is stumping me as the width, depth etc. can all change on a product by product basis. Any suggestions?

Full String:

Test CPL560 Home Office Corner WorkstationExecutive, designer style corner workstation. The smart-looking, functional CPL560 with complementing side storage unit featuring high gloss black drawer fronts, provides the perfect solution for the modern, spacious home office. Quality 32mm desktop measuring 1600x700mm, finished with  2mm ABS edge protection providing a comfortable, durable finish. The desktop rear wall features cable guide and rear cable housing. The side return storage unit of the Test CPL560 corner computer desk rotates through 360 degrees to allow the side return to be located and fixed on either the right or left hand side of the desk top, whichever best suits your working position and home office layout. The side return unit comprises 3 push-to-open storage drawers with high gloss drawer fronts, a CPU storage compartment with rear cable management and 2 further storage compartments with one height adjustable shelf. CPL560 Corner Workstation is available in White/High Gloss BlackOptional installation/assembly available for this product  free delivery5-7 working days  assembly required?Yes   guarantee2 years  dimensions(mm) Width:  1600-2340  Depth:  700-1350  Height: 760

What I want:

Test CPL560 Home Office Corner WorkstationExecutive, designer style corner workstation. The smart-looking, functional CPL560 with complementing side storage unit featuring high gloss black drawer fronts, provides the perfect solution for the modern, spacious home office. Quality 32mm desktop measuring 1600x700mm, finished with 2mm ABS edge protection providing a comfortable, durable finish. The desktop rear wall features cable guide and rear cable housing.

The side return storage unit of the Test CPL560 corner computer desk rotates through 360 degrees to allow the side return to be located and fixed on either the right or left hand side of the desk top, whichever best suits your working position and home office layout. The side return unit comprises 3 push-to-open storage drawers with high gloss drawer fronts, a CPU storage compartment with rear cable management and 2 further storage compartments with one height adjustable shelf. CPL560 Corner Workstation is available in White/High Gloss BlackOptional installation/assembly available for this product

I'm not bothered about where the paragraphing takes place, only to make it semi readable. Is this possible via preg_replace or regex?

You can try this:

$result = str_replace(' ', ' ', $text);
$result = str_replace($prName, '', $result);
$result = preg_replace('~^.*?yreviled eerf +~', '', strrev($result));
$result = strrev($result);

The text where it's a pattern with values that can change, a regular expression based search and replace can make it.

But before that I would normalize the text, e.g. replacing the   with spaces and two or more spaces with a single space etc.. But that step only if you don't need the "dirt" to figure out which parts to remove. In that case remove first, then normalize.

You should be able to do this in multiple passes, if you know all scenarios of possible "ending text" that can exist. First of all you can convert the   to spaces with either

$string = str_replace(' ', ' ', $string);

or

$string = html_entity_decode($string, ...);

You can then tokenize the words with explode(' ', $string); to get a large array of words, then step over the words to detect exact matches like Width:, Height:, or free delivery to strip them out into an attributes array. Rejoin the main description with implode(' ', $words);