首页 > 解决方案 > 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]&#039;s customer.<\/span><\/p>","numbering":""},"children":[]}  
[2020-04-06 11:05:12] local.INFO: Receiving response:{"content":{"content":"<p><span>they become the [Y]&#039;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]&#039;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]&#039;s written consent.<\/span><\/p>","numbering":""},"children":[]}  

标签: php

解决方案


推荐阅读