0

I have a class which is working fine but I need to do multiple results.

Here is the current code:

$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"].".";

}

What is the best way to get it to read multiple url's / keyword's ?

2
  • What's RankChecker? Commented Apr 3, 2014 at 15:51
  • show what you have, and what you want (result) Commented Apr 3, 2014 at 15:52

2 Answers 2

1

Put the URLs and keywords into an array and loop through it:

$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"].".";

    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Using an array :

<?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"].".";

    }   
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.