Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top