dongtiaobeng7901 2016-03-18 10:28
浏览 216
已采纳

从字符串中提取ip地址[重复]

This question already has an answer here:

I have following string an want to exctract the ip-address:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Hier k&ouml;nnen Sie sich Ihre eigene IP Adresse anzeigen lassen, sehen &uuml;ber welchen Host Sie surfen, woher Sie kommen, welchen Browser Sie nutzen und &uuml;ber welchen Link Sie zu dieser Seite gefunden haben.">
                <link rel="icon" href="/favicon.ico">

        <title>Meine IP Adresse ermitteln &amp; anzeigen &ndash; Geokodierung, Host, Herkunft, Browserkennung (User Agent) &amp; Referer</title>

        <link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet" type="text/css">
        <link href="/css/font-awesome.min.css" rel="stylesheet">
        <link href="/css/bootstrap.min.css" rel="stylesheet">
        <link href="/css/styles.css" rel="stylesheet">
        <link href="/css/dark-bottom.min.css" rel="stylesheet">

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>

    <body>
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          ga('create', 'UA-6321715-14', 'auto');
          ga('require', 'linkid');
          ga('require', 'displayfeatures');
          ga('send', 'pageview');
        </script>

        <div class="container">
            <div class="header clearfix">
                <h3>ueber-mich.com</h3>
                <nav>
                    <ul class="nav nav-pills pull-right">
                        <li class="active"><a href="/">Startseite</a></li>
                        <li>
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Glossar <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li class=""><a href="/ip-adresse/">IP-Adresse</a></li>
                                <li class=""><a href="/hostname/">Hostname</a></li>
                                <li class=""><a href="/whois/">Whois</a></li>
                                <li class=""><a href="/user-agent/">User-Agent</a></li>
                                <li class=""><a href="/referrer/">Referrer</a></li>
                                <li class=""><a href="/bildschirmaufloesung/">Bildschirmaufl&ouml;sung</a></li>
                                <li class=""><a href="/pixeldichte/">Pixeldichte</a></li>
                                <li class=""><a href="/farbtiefe/">Farbtiefe</a></li>
                            </ul>
                        </li>
                        <li class=""><a href="/datenschutz/">Datenschutz</a></li>
                        <li class=""><a href="/impressum/">Impressum</a></li>
                    </ul>
                </nav>
            </div>

<div class="jumbotron">
            <span class="label label-info"><a href="/ip-adresse/">IP-Adresse (IPv4)</a></span><strong class="ip">176.<wbr>199.<wbr>114.<wbr>9</strong>
                <span class="label label-hostname"><a href="/hostname/">Hostname</a></span><span class="hostname">ip-<wbr>176-<wbr>199-<wbr>114-<wbr>9.<wbr>hsi06.<wbr>unitymediagroup.<wbr>de</span>
                <br>        <span class="label label-hostname"><a href="/whois/">Whois</a></span><span class="whois">Unitymedia dynamic customer IP pool (Unitymedia Group)</span>
    </div>

<div class="jumbomap" style="background-image:url('map/?lng=8.0885&lat=51.5602&z=9')">
    <div class="location">
                    <span class="label label-info">Herkunft</span>
            <img src="img/flags/de.png">        Deutschland &raquo; Nordrhein-Westfalen &raquo; Soest   </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <table>
            <tbody>
                <tr>
                    <th><span class="label label-info"><a href="/user-agent/">User-Agent</a></span></th>
                    <td>Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9</td>
                </tr>
                <tr>
                    <th><span class="label label-info"><a href="/referrer/">Referrer</a></span></th>
                    <td>http://twitter.de</td>
                </tr>
                <tr>
                    <th><span class="label label-info"><a href="/bildschirmaufloesung/">Bildschirm&shy;aufl&ouml;sung</a></span></th>
                    <td class="bildschirmaufloesung"><span class="muted">&mdash;</span></td>
                </tr>
                <tr>
                    <th><span class="label label-info"><a href="/pixeldichte/">Pixeldichte</a></span></th>
                    <td class="pixeldichte"><span class="muted">&mdash;</span></td>
                </tr>
                <tr>
                    <th><span class="label label-info"><a href="/farbtiefe/">Farbtiefe</a></span></th>
                    <td class="farbtiefe"><span class="muted">&mdash;</span></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<div class="row intro">
    <div class="col-lg-12">
        <h1>Die eigene IP-Adresse ermitteln &amp; anzeigen</h1>
        <p>ueber-mich.com hilft dabei, Ihre eigene IP Adresse und weitere Details (Host, User-Agent, Referer, Auflösung, Farben) über Ihren Computer und dessen Aufenthaltsort herauszufinden und anzuzeigen.</p>
    </div>
</div>

            <footer class="footer text-center">
                <p>&copy; 2006&ndash;2016 <a href="http://www.udg.de/koeln">UDG K&ouml;ln</a> GmbH</p>
            </footer>

        </div>

        <script src="/js/ie10-viewport-bug-workaround.js"></script>
        <script src="/js/jquery.min.js"></script>
        <script src="/js/bootstrap.js"></script>
        <script src="/js/scripts.js"></script>
        <script src="/js/cookieconsent.min.js"></script>
    </body>
</html>

i want to extract that:

176.<wbr>199.<wbr>114.<wbr>9

in a string in this format: 176.199.114.9

i have tried it with:

preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}/",$result,$ip);
echo $ip; 

and my output just

Array
</div>
  • 写回答

3条回答 默认 最新

  • douyanti2808 2016-03-18 10:52
    关注

    if you get to a point where you have the IP mixed with a couple of tags, you could simple appy the php function strip_tags() to it:

    $ip = "176.<wbr>199.<wbr>114.<wbr>9";
    $cleanIp = strip_tags($ip); //output 176.199.114.9
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器