Php 如何使用simple_html_dom替换元素

Php 如何使用simple_html_dom替换元素,php,Php,我正在使用simple_html_dom解析元素 以下是输出: <span id="time1">4:00 PM </span> - <span id="title1">The Real Housewives of New York City"If You Can Make It Here"</span><br><br><span id="time2">5:00 PM </span> - <sp

我正在使用simple_html_dom解析元素

以下是输出:

<span id="time1">4:00 PM </span> - <span id="title1">The Real Housewives of New York City"If You Can Make It Here"</span><br><br><span id="time2">5:00 PM </span> - <span id="title2">The Real Housewives of New York City: Give Up the Ghostwriter:    </span><br><br>
它将双引号替换为:。我只想替换两个文本之间的单引号

例如:

The Real Housewives of New York City: If You Can Make It Here
如您所见,我想替换文本City和If之间的单引号。我想让它看起来像这样:

$output1 = str_replace('"', ':', $output1);
                         PM                                                                                                                                                                                                       The Real Housewives of Beverly Hills                                                                                               : Reunion Part 3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                TV-14                                                                                                                                                                                                                                                                                                                                                                                                                                            &nbsp;(D,L)                                                                                                                                                                                                        <span id="time1">7:00 PM </span> - 
当我尝试这样做时:

The Real Housewives of New York City"If You Can Make It Here"
The Real Housewives of New York City: If You Can Make It Here:
我会得到这样的东西:

$output1 = str_replace('"', ':', $output1);
                         PM                                                                                                                                                                                                       The Real Housewives of Beverly Hills                                                                                               : Reunion Part 3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                TV-14                                                                                                                                                                                                                                                                                                                                                                                                                                            &nbsp;(D,L)                                                                                                                                                                                                        <span id="time1">7:00 PM </span> - 
请告诉我,如果元素在文本中间有一个引号,我可以如何检查元素,即使我不想替换元素结尾的单个引号?

我如何替换元素末尾的文本,用空文本替换单引号

编辑:以下是输出:

<span id="time1">4:00 PM </span> - <span id="title1">The Real Housewives of New York City"If You Can Make It Here"</span><br><br><span id="time2">5:00 PM </span> - <span id="title2">The Real Housewives of New York City: Give Up the Ghostwriter:    </span><br><br>

您可以传入一个限制:str_replace“”,“:”,$output1,1,然后再次运行它以除去结束引号:str_replace“”,$output1,1@scrowler谢谢你,我试着用你刚才说的,但是没有用,因为我会得到一个没有错误的空输出。你能提供我应该使用的正确来源吗?基本资料:$output1=str_replace',':',$output1,1$output1=str_替换“”,$output1,1@我试过了,但不管用。我只有一页空白。我的php页面中没有错误,所以我不确定出了什么问题?空页面意味着您有一个解析错误或语法错误,而您的服务器没有显示给您。您应该始终将本地或开发服务器上的错误报告级别调到尽可能高的级别,以捕获这些错误。把它放在PHP脚本的顶部:error_reportingE_ALL;