dpp78272 2018-06-30 05:45
浏览 41
已采纳

如何使用php正则表达式进行描述?

Iam making a webcrawler and I need to extract the metadata that contains the description, this is what I did:

$html = file_get_contents('http://www.google.com');
preg_match('/<meta name="description" content="(.*)"/>\i', $html, $description);
$description_out = $description;
var_dump($description_out);

and I get this error

Warning: preg_match(): Unknown modifier '>' in C:\xampp\htdocs\webcrawler\php-web-crawler\index.php on line 21

What is the correct regular expression?

  • 写回答

2条回答 默认 最新

  • dongshi8359 2018-06-30 05:57
    关注

    Your pattern is incorrect. You start with a / delimiter and then you have an unescaped / in the pattern this ends the pattern and everything after it is read as modifiers.
    Then your end delimiter was on the wrong way, was \ should be /.

    '/<meta name="description" content="(.*)"\/>/i',
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效