使用PHP更改/编辑标签

这是我在这里的第一个问题所以请耐心等待 – 如果我没有正确发布,我道歉.

我已经设法从我们的数据库创建的XML文件提取作业描述,但是,数据库软件非常陈旧并且它会转换某些
 字符.

我的问题如下:子弹点转换为如下所示:

"   Production of Monthly Management Accounts and variance analysis<BR>

因此,在点应该是的位置输入“(引号)”并输入< BR>以开始新行.

我想知道是否有人知道如何转换引号和< BR>到< li>和< / li> repspectively.
我一直在寻找多个选项,比如preg_match和substr_replace,但是,它们都没有给出所需的结果.

显然,< li>之间的文字.和< / li>会因工作等而改变

最重要的是,一旦这个工作,我需要能够添加< ul>和< / ul>围绕列表项,但我想我可以找到< li>的第一个实例并替换为< ul>< li>同样是< / li>的最后一个例子并替换为< / li>< / ul>.

对不起,我很抱歉,我希望自己能说清楚.

编辑:
非常感谢所有的快速反应,我明天会给这些打击.我大部分时间都被困在这一天,所以认为是时候离开了.

只是为了给它一些额外的信息,如果它有帮助……

数据库软件大约有12年的历史,对它的支持是非常有限的.如果我们想要做某事,往往会花费很多钱.它有一些导出数据的选项,然而,无论出于什么原因,XML都保留了HTML格式,所以我选择了这条路线.

所有作业都先用Word编写,然后粘贴到数据库中的“作业字段”中,因此代码错误解释的可能性很大.

我做了一个测试工作,并确保我在Word中使用了子弹点并将其复制 – 粘贴到“工作区”中,引号出现在点应该是的位置,所以我假设旧软件不“理解”子弹点.

我将尽力回复您的所有回复并明天回复

谢谢!

编辑2

嗨,下面我已经粘贴了源视图的实际输出.
我已经尝试过下面的preg_replace选项,它可以在一行上运行,但正如你所看到的那样输出是令人烦恼地连续放置所有内容而没有换行符.

An exciting opportunity has arisen to join an established company based in Luton for a high calibre Management Accountant. Reporting to the Finance Director, the Management Accountant will provide accurate and reliable management information and financial support to the business. <BR>Key Responsibilities:<BR>" Production of Monthly Management Accounts and variance analysis<BR>"    Preparation of Management Reports for Management Meetings.<BR>" Production of Monthly Forecasts and Annual Budgets using Excel.<BR>"    Decision support to the business<BR>"   Attending and presenting at meetings with business managers<BR>"    Assisting external auditors with their audit process at each year end<BR>"  Ad-hoc project work<BR>Experience:<BR>" Qualified accountant (ACA or CIMA) <BR>"    Strong communication skills - to communicate effectively with all levels of management<BR>" High level of personal motivation, focus and a commitment to quality<BR>"   Ability to adapt to the demands of a constantly changing business<BR>"  Ability to interact with people at all levels in a sensitive and effective way<BR>If you are interested in this role then please apply Now.<BR>

解决方法:

假设:

>“开始行(引用后跟3个空格,markdown删除空格)
>< BR>就在最后
>没有其他变化,也没有分割线

正则表达式:

/^"   (.*)<BR>$/

PHP

$replacedData = preg_replace( '/^"   (.*)<BR>$/', '<li>\1</li>', $data );

正如你所说的那些内容都集中在一起,你可以试试这个正则表达式:

/"   (.*?)<BR>/

虽然你应该被警告,如果这些行恰好包含“引用”文本,它可能会收到错误的引用.

或者,如果你知道这些行以< BR>“结尾(由于降价而删除了3个空格),你可以使用3个替换来获得所需的效果

$repData = preg_replace(
             array( '/<BR>"   /', '<BR>', '"   ' ),
             array( '</li><li>', '</li></ul>', '<ul><li>' ),
             $data );

同样,这可能会选择错误的元素,特别是如果< BR>存在于代码的其他地方.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...