duanci8209
2018-08-17 20:23
浏览 283
已采纳

PHP str_replace使用通配符刮取内容?

I'm looking for a solution to strip some HTML from a scraped HTML page. The page has some repetitive data I would like to delete so I tried with preg_replace() to delete the variable data.

Data I want to strip:

Producent:<td class="datatable__body__item" data-title="Producent">Example
Groep:<td class="datatable__body__item" data-title="Produkt groep">Example1
Type:<td class="datatable__body__item" data-title="Produkt type">Example2
.... 
...

Must be like this afterwards:

Producent:Example
Groep:Example1
Type:Example2

So a big piece is the same except the word within the data-title piece. How could I delete this piece of data?

I tried a few things like this one:

$pattern = '/<td class=\"datatable__body__item\"(.*?)>/';
$tech_specs = str_replace($pattern,"", $tech_specs);

But that didn't work. Is there any solution to this?

图片转代码服务由CSDN问答提供 功能建议

我正在寻找一种从已删除的HTML页面中删除一些HTML的解决方案。 该页面有一些我想要删除的重复数据,所以我尝试使用preg_replace()删除变量数据。

我要删除的数据: < pre> Producent:&lt; td class =“datatable__body__item”data-title =“Producent”&gt;示例 Groep:&lt; td class =“datatable__body__item”data-title =“Produkt groep”&gt; Example1 Type: &lt; td class =“datatable__body__item”data-title =“Produkt type”&gt; Example2 .... ...

必须像 之后:

  Producent:Example 
Groep:Example1 
Type:Example2 
   
 
 

所以一大片是 除了数据标题片段中的单词之外。 我怎么能删除这段数据呢?

我尝试过这样的一些事情:

  $ pattern ='/&lt;  td class = \“datatable__body__item \”(。*?)&gt; /'; 
 $ tech_specs = str_replace($ pattern,“”,$ tech_specs); 
   
 
 < 但是那没用。 有没有解决方案? 
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题