【发布时间】:2013-09-03 15:53:20
【问题描述】:
我有一个描述,其中包含我要删除的两段文本和要格式化的文本。该字符串可以更改并且其中包含  和空格(这是错误数据)。
我需要同时删除产品名称和末尾的一段文本(两者都可以根据“产品”进行更改)。我将产品名称存储为如下变量:
$prName = "Test CPL560 Home Office Corner Workstation";
需要删除的末尾文本如下:
free delivery5-7 working days  assembly required?Yes   guarantee2 years  dimensions(mm) Width:  1600-2340  Depth:  700-1350  Height: 760
删除产品名称应该相当简单,但最后一段文字让我很困惑,因为宽度、深度等都可能因产品而异。有什么建议吗?
完整字符串:
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
我想要什么:
测试 CPL560 家庭办公室角落工作站行政,设计师风格的角落工作站。外观时尚、功能齐全的 CPL560 带有互补的侧储物单元,具有高光黑色抽屉正面,为现代、宽敞的家庭办公室提供了完美的解决方案。优质 32 毫米桌面尺寸为 1600x700 毫米,采用 2 毫米 ABS 边缘保护,提供舒适、耐用的饰面。桌面后壁具有电缆引导器和后电缆外壳。
Test CPL560 转角电脑桌的侧边回位存储单元可 360 度旋转,以便将侧边回位定位并固定在桌面的右侧或左侧,以最适合您的工作位置和家庭的为准办公室布局。侧面返回单元包括 3 个带高光泽抽屉正面的推开式储物抽屉、一个带后部电缆管理的 CPU 储物箱和 2 个带一个高度可调节搁板的其他储物箱。 CPL560 转角工作站有白色/高光黑色可供此产品选择安装/组装
我不关心分段发生在哪里,只是为了让它半可读。这可以通过 preg_replace 或 regex 实现吗?
【问题讨论】:
-
创建时不能清理吗? IE 如果来自数据库,使用实体等。只是一个想法。如果可能,产生好的结果比清理坏的结果更好
-
我完全同意詹姆斯,但是这将是一个太好的想法来实现(如果你明白我的意思!)。我无法访问或控制源数据库或数据,只有可怜的草皮必须清理它。如果我一开始就接触到它,这将永远不会发生。
-
我认为为上下文解析英语有点困难。它可能无法撤消。
标签: php regex string preg-replace data-manipulation