0

I am using a class from Imran Omer on this thread Check PageRank Through XML to get pagerank.

It is working great. The only problem I got here is I couldn't get the blank value. What I get is 0 is equal to ''.

Here is what I mean:

Let's assume that domain.com PR is blank or no value, example.com PR is 0 and yoursite.com is 1.

With the class I mentioned above, I want to retrieve their pagerank and output string N/A if the pagerank is not 0, 1 or bigger.

So, the code would be something like this:

$allurls = array('domain.com', 'example.com', 'yoursite.com');

foreach( $allurls as $url) {

$pr = GooglePageRankChecker::getRank($url);

if ($pr >= 0) {
echo $pr . ' ';
} else {
echo "N/A";
}

}

But it returns just like this:

0 1 instead of N/A 0 1

I had tried empty and is_null, but it still can not recognize the blank value.

How to make it recognize blank value and not confuse it with 0 so I can output 'N/A' when the pagerank is blank?

Best Regards

Community
  • 1
  • 1
Ari
  • 4,643
  • 5
  • 36
  • 52
  • Have you checked, what exactly is returned by the `GooglePageRankChecker` method in that case? Using `var_dump()` for example. – Sirko Feb 23 '14 at 17:26
  • 1
    have you tried `if (trim($pr) != '')` ? If that is not working you should check what exactly ::getRank() returns. – MSadura Feb 23 '14 at 17:27
  • @Sirko Not yet Sirko. – Ari Feb 23 '14 at 17:35
  • @MarkS Not yet MarkS, Would you like to provide it as an answer so I can accept it? It work! – Ari Feb 23 '14 at 17:36

1 Answers1

1

According to your class $result is by default set:

$result = "";

So you should check your condidtion like this:

if (trim($pr) != '')

Note - trim is just to make sure there is no whitespace, should work even without it.

Answer as requested in comment.

MSadura
  • 1,032
  • 13
  • 18