Hi folks, I'm looking for help with an if statement and showing a logo. I have a pagerank checker and I want to show a gif of a PR button along with the PR result. But not sure how to code it... This is part of the code that returns the PR: //get google pagerank function getpagerank($url) { $query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0"; $data=file_get_contents_curl($query); //print_r($data); $pos = strpos($data, "Rank_"); if($pos === false){} else{ $pagerank = substr($data, $pos + 9); return $pagerank; } } PHP: And this is the code that shows the PR: <?php $url=$_REQUEST['url']; echo "Google Pagerank = PR".getpagerank($url)."<br />"; ?> PHP: So if the result is PR4 then I also want to show a gif of and the picture changes with every PR results. Does that make sense? And also offer code so that people can put that icon on their website. Any help is apprecaited! Thank you!
If ($pagerank==4) { echo "<img scr './pr_icons/pr4.gif '>"; } If ($pagerank==5) { echo "<img scr './pr_icons/pr5.gif '>"; } Repeat process for as many as you like. You need to do the second part as a text area that they can copy and link to the image on your site.
The $pagerank variable is in another file but the file is called at the top of the script page. Let me explain, I have a pr.php file to display the contents of the script and the pagerank_lib.php file that does all the fetching of data and calculating. This line is at the top of the pr.php file... require_once("pagerank_lib.php"); Code (markup): So would the $pagerank variable work in the pr.php file? I can't get it to work using your above advice. I also changed it to this because it thought you had missed a few characters out... if ($pagerank==4) { echo "<img scr='/pr_icons/pr4.gif'>"; } Code (markup):
It's cool, I managed to figure it out! if ( getpagerank($url) == 4 ) { echo "<img src='/pr_icons/pr4.gif'>"; } Code (markup): Thanks for the starter!
The switch statement might be a tad faster but I don't think it will matter a lot. I can't write one of those on the fly. Yep I missed the = sign for sure. Glad you got it working.
Wow, forget the switch. Can't believe it took me so long to think of this. Just do $pagerank_no = getpagerank($url); ?> <img src="/pr_icons/pr<?php echo $pagerank_no ?>.gif"> PHP: Should work.
But use that after: $pagerank_no = getpagerank($url); That makes it 2 lines of code and is a much better solution.
This is what I ended up using... echo "Google Pagerank = <img src='/pr_icons/pr".getpagerank($url).".gif'><br />"; PHP: But I did use the if statements for another purpose so I did need to know how to do it!
$pagerank = getpagerank($url); if ($pagerank == "N/A"){ echo "the page rank is unknown"; } else { echo "<img scr='/pr_icons/pr".$pagerank.".gif'>"; } PHP:
Ah good thinking hehe. Unfortunately it doesn't like the "N/A". Is there a way I can say...if $pagerank does not equal a number? Or if $pagerank is not between 0 and 10, maybe in an array? Thanks for all your help!
if (ctype_digit(getpagerank($url))){ echo "Google Pagerank = <img src='/pr_icons/pr".getpagerank($url).".gif'><br />"; } else { echo "Google Pagerank = <img src='/pr_icons/prna.gif'><br />"; } PHP:
Thanks for your continued help qualityfirst but that didn't work. No matter what site I use, it always shows the 'else' option, i.e. no pr.
Try this $pagerank1 = getpagerank($url); if (ctype_digit($pagerank1){ echo "Google Pagerank = <img src='/pr_icons/pr".$pagerank1.".gif'><br />"; } else { echo "Google Pagerank = <img src='/pr_icons/prna.gif'><br />"; } PHP: