使用 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 function to delete all between certain character(s) in string
但是当我尝试将其投入使用时,我没有找到匹配项。
$contents = delete_all_between('<br/>©', '</a>', $contents);
$contents = delete_all_between('<br/>©', '</a>', $contents);
我试过使用 © 符号和 & # 169;和其他一些变体,但我没有想法。
我想这很简单,希望这里有人能把我从痛苦中解救出来。
这可以用 PHP 中的正则表达式完成。这是一个例子:
$text = "All of your stuff. @This will be deleted";
echo preg_replace("/(@.+)(<)/", "", $text);
简单地说,上面的代码将替换所有以 @
和结束标记开头的代码。
检查您使用的文档的编码。创建版权符号的更常见方法是 ©
Copyright encodings
背景:我们正在合并一些文档的页面,使它们看起来像一个漂亮的长页面,而不是分成数百个。为此,我们需要从每页底部删除页码、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 function to delete all between certain character(s) in string
但是当我尝试将其投入使用时,我没有找到匹配项。
$contents = delete_all_between('<br/>©', '</a>', $contents);
$contents = delete_all_between('<br/>©', '</a>', $contents);
我试过使用 © 符号和 & # 169;和其他一些变体,但我没有想法。
我想这很简单,希望这里有人能把我从痛苦中解救出来。
这可以用 PHP 中的正则表达式完成。这是一个例子:
$text = "All of your stuff. @This will be deleted";
echo preg_replace("/(@.+)(<)/", "", $text);
简单地说,上面的代码将替换所有以 @
和结束标记开头的代码。
检查您使用的文档的编码。创建版权符号的更常见方法是 ©
Copyright encodings