如何使用php在外部网站中查找单词


how to find a word in an external website with php

如何使用PHP在外部页面中查找特定单词?此页面受登录区域保护。有可能做点什么吗?

<?php 
$v = file_get_contents("http://it.website.com");
echo substr_count($v, 'web'); // number of occurences
//or single match
echo substr_count($v, ' abcd ');
?>

我的问题是自动通过登录。。

登录形式:

<form name="login" action="/login.php" method="post" onsubmit="return check(this);">
<div class="row">
    <div class="form-group">
        <div class="col-md-12">
            <label>Email o Nome utente</label>
            <input type="text" value="" name="user_email" class="form-control input-lg">
        </div>
    </div>
</div>
<div class="row">
    <div class="form-group">
        <div class="col-md-12">
            <label>Password</label>
            <input type="password" value="" name="user_pass" class="form-control input-lg">
        </div>
    </div>
</div>
<div class="row">
<div class="col-md-12">
        <input type="submit" value="Accedi" name="login" class="btn btn-primary pull-right push-bottom" data-loading-text="Loading...">
        <input type="hidden" name="mode" value="checklogin" id="login">
    </div>
</div>

您可以尝试这个代码片段(需要PHP 5+,对于旧版本请询问)
当按下Accedi按钮时,它会发送POST请求:

$url = 'http://it.website.com/login.php';
$para = array(
    'user_email' => 'myname@example.com',
    'user_pass'  => 'MySuperSecretPassword',
    'mode'       => 'checklogin', // the hidden field in the form
);
$opts = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded'r'n",
        'method'  => 'POST',
        'content' => http_build_query($para),
    )
);
$ctxt  = stream_context_create($opts);
$page = file_get_contents($url, false, $ctxt);
if ($page !== false) {
    // $page contains the page returned by the web server
    echo substr_count($page, ' abcd ');
    echo substr_count($page, 'web');
}

注意:user_emailuser_pass,隐藏的模式字段和url部分/login.php取自<表单>hellip<表单>密码也许看看检查(这个)是个好主意函数。