doukang5966907 2013-11-05 08:29
浏览 15
已采纳

使用preg_match从此html中截取经度和纬度

I'm trying to use a regex to extract just the longitude and latitude coordinates from this html. This is just a snippet of the full html from http://www.bricodepot.fr/troyes/store/storeDetails.jsp?storeId=1753 so I need to be able to search through the whole targets page html and match the longitude and latitude from this block:

<div class="coordinates">
    <i></i>
    <strong>Latitude :</strong> 46.369384765625<strong>Longitude :</strong> 2.56929779052734</div>
</div>

This is about as close as I can get at the moment:

preg_match("/<strong>Latitude :<\/strong> (.*?)/", $input_line, $output_array);

which gives:

Array ( [0] => Latitude : [1] => )

Any idea how I can get the cordinates?

  • 写回答

3条回答 默认 最新

  • doulu1325 2013-11-05 08:33
    关注

    You're almost there!

    preg_match_all("<strong>L(at|ong)itude :<\/strong>\s([\w\.]*)?", $input_line, $output_array);
    

    And the resulting array will be something like:

    Array
    (
        [0] => Array
            (
                [0] => <strong>Latitude :</strong> 46.369384765625
                [1] => <strong>Longitude :</strong> 2.56929779052734
            )
    
        [1] => Array
            (
                [0] => at
                [1] => ong
            )
    
        [2] => Array
            (
                [0] => 46.369384765625
                [1] => 2.56929779052734
            )
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥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之后自动重连失效