Tuesday, 3 September 2013

Preg_replace replace specific phrase

Preg_replace replace specific phrase

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?

No comments:

Post a Comment