删除以©(版权所有)符号使用PHP


Removing lines that begin with © (copyright) symbol using PHP

背景:我们正在合并一些文档的页面,使它们看起来像一个漂亮的长页面,而不是分成数百个。为此,我们需要从每页底部删除页码、HR标签和版权声明,然后手动将版权声明添加到最后一页。我们已经找到了一个简单的模式来识别页脚,并在下面概述了它。

为了清理页脚,我试图删除br和版权符号之间的所有文本以及结束标签

In the beginning the universe was created.
<br/>© 2010 Some message here<br/>
<hr/>
<a name=3></a>
This has made a lot of people very angry and been widely regarded as a bad move.

预期结果:

In the beginning the universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.
我发现最有希望的代码是这里:PHP函数删除字符串

中特定字符之间的所有字符

但是当我试着把它投入使用时,我没有得到匹配。

    $contents = delete_all_between('<br/>©', '</a>', $contents);
    $contents = delete_all_between('<br/>&#169;', '</a>', $contents);

我试过使用©符号以及&# 169;和一些其他的变化,但我没有主意。

我怀疑这很简单,希望有人能把我从我的痛苦中解脱出来。

这可以用PHP中的正则表达式来完成。下面是一个例子:

$text = "All of your stuff. @This will be deleted";
echo preg_replace("/(@.+)(<)/", "", $text);

简单地说,上面的代码将替换所有以@开头和结束标记的代码。

检查正在处理的文档的编码。更常见的创建版权符号的方法是&copy;版权编码