php - str_replace 仅适用于 foreach 中的第一个元素
问题描述
我尝试<p>
从字符串中删除所有内容,但在我的情况下仅适用于 foreach 中的第一个元素。
$fullstring = '<ul>';
foreach ($item['children'] as $key => $sub_item) {
$nextElement = str_replace(array("<p>", "</p>"), array("", ""), $sub_item['content']['content']);
$fullstring .= '<li>' . $nextElement . '</li>';
}
$fullstring .= '</ul>';
得到的响应(来自日志)$sub_item
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>The [X] is paid for all of the Products and no other amounts are owed by the [Y] to the [X] in respect of other Products supplied by the [X].<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>The [Y] sells the Products in accordance with this agreement in which case ownership of the Products will pass to the [Y] immediately before the Products are delivered to the [Y]'s customer.<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>they become the [Y]'s property; or<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>they are attached to or incorporated in other Products; or<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>they are delivered to a purchaser from the [Y].<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>If the [Y] sells the Products, the [Y] shall hold the proceeds of sale on trust for the [X] in a separate bank account.<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>The [X] may trace the proceeds of sale that the [Y] receives into any bank or other account which the [Y] maintains.<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>If the [Y] sells the Products, the [X] may, by written demand, require the [Y] to assign to the [X] the [Y]'s rights to recover the price from its customer.<\/span><\/p>","numbering":""},"children":[]}
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>The [Y] must not assign to any other person any rights arising from a sale of the Products without the [X]'s written consent.<\/span><\/p>","numbering":""},"children":[]}
解决方案
推荐阅读
- content-security-policy - 随机数与自定义数据。客户端是nonce=还是nonce-?客户端也是nonce-xyz还是'nonce-xyz'
- sql - PostgreSQL:一张表上的子查询
- r - 如何在 R 中添加对数回归
- ios - iOS 自定义 B2B 应用程序在使用兑换码下载时会自动更新吗?
- python - 在Django中过滤时过滤数据/忽略空值
- moodle - moodlecloud 3.9.2 上缺少安装插件选项
- android - Resource Owner Password Credentials Grant 的使用有效时
- python - 将字符串转换为 unicode 视图
- python - 我如何在 Python 中使用 GCP 枚举?
- angular - 如何在角度的 p-editor 上使用 ql-image 添加验证?