从HTML数据字符串中获取特定信息

时间:2018-03-20 13:03:31

标签: php web-scraping

我有以下格式的数据,该格式已分配给变量$ data,其中我只是尝试获取Product DescriptionIngredients,并将它们分配给变量$pdesc& $ingredient。 PHP中有没有办法提取这些特定信息?所以在下面的例子中。

$pdesc should contain "<p>It can help improve brain and memory function</p>
  <p>Its good for health</p>"  
$ingredients should contain "<p>Lecithin (product of soya), Gelatin, Glycerine.  </p>" 
$data = '<div id="productDescription">

  <div class="disclaim">

    Size:<strong>90</strong>

  </div>

  <h3>Product Description</h3>
  <p>It can help improve brain and memory function</p>
  <p>Its good for health</p>

  <h3>Indications</h3>

  <p>Do not exceed the recommended intake.  </p>

  <h3>Ingredients</h3>

  <p>Lecithin (product of soya), Gelatin, Glycerine.  </p>

  <h3>Directions</h3>

  <p>Take 1 - 2 softgels per day with food.  </p>

  <h3>Box Contains</h3>

  <p>1 x Natures Aid 1200mg Soya Lecithin 90 Capsules</p>

</div>'

1 个答案:

答案 0 :(得分:-1)

你可以使用php explode功能可能是你的帮助。了解有关爆炸https://www.phpkida.com/php-tutorial/multi-explode-multiple-delimiters-pass-php/

的更多信息