我下面有一些这样的文字,我想要的是删除最后一个地址匹配,问题是这些地址有不同的格式,取决于文字:
我有这个:
To find out more about Groupon Goods, see the <a href="http://www.groupon.co.uk/faq"> FAQ</a>.\n\nUK-Bedding Returns:Albany Mill, Old Hall Street, Middleton, Manchester M241AG
UK-Bedding Returns:Albany Mill, Old Hall Street, Middleton
Manchester M241AG\n\n<a href="http://www.groupon.co.uk/terms_and_conditions"></a>
Built by gskinner.com with Fl
输出应该是这个(我已经删除了最后一个“奥尔巴尼磨坊,老霍尔街,米德尔顿 曼彻斯特M241AG“):
To find out more about Groupon Goods, see the <a href="http://www.groupon.co.uk/faq"> FAQ</a>.\n\nUK-Bedding Returns:Albany Mill, Old Hall Street, Middleton, Manchester M241AG
UK-Bedding Returns:\n\n<a href="http://www.groupon.co.uk/terms_and_conditions"></a>
Built by gskinner.com with Fl
答案 0 :(得分:1)
如果总是有重复,我会采取不同的方式:
所以,在你的例子中,类似(额外详细):
$lines = preg_split('#\n+#', $text);
$addresses = $lines[1];
$address = substr($addresses, 0, floor(strlen($addresses) / 2));