我有一个工作正常的课程,但我需要做多个结果。
以下是当前代码:
$url = 'http://mydomain.com';
$keyword = 'somekeyword';
$RankChecker=new RankChecker(1,5);
$result=$RankChecker->find($url,$keyword);
if ($result!==false) {
echo "Your website is found at page number ".$result["page"].".";
}
让它读取多个网址/关键字的最佳方式是什么?
答案 0 :(得分:1)
将URL和关键字放入数组并循环遍历:
$urls = array(
'http://mydomain.com' => 'somekeyword',
'http://myotherdomain.com' => 'someotherkeyword'
);
$RankChecker=new RankChecker(1,5);
foreach($urls as $url => $keyword) {
$result=$RankChecker->find($url,$keyword);
if ($result!==false) {
echo "Website " . $url . " is found at page number ".$result["page"].".";
}
}
答案 1 :(得分:1)
使用数组:
<?php
$websites[1] = array('url' => 'http://mydomain.com', 'keyword' => 'somekeyword');
$websites[2] = array('url' => 'http://mydomain2.com', 'keyword' => 'somekeyword2');
$websites[3] = array('url' => 'http://mydomain3.com', 'keyword' => 'somekeyword3');
// etc...
foreach ($websites as $val)
{
$RankChecker=new RankChecker(1,5);
$result=$RankChecker->find($val['url'], $val['keyword']);
if ($result!==false) {
echo "Your website is found at page number ".$result["page"].".";
}
}