code
Valid XHTML flash embed code
On 17, Feb 2010 | One Comment | In Flash, XHTML | By abcoder
You’ll be disheartened for the first time when you attempt to validate your flash embedded html page on W3C. Here is the basic structure for valid swf embed code:
<object type="application/x-shockwave-flash" data="movie.swf" width="250" height="25"> <param name="movie" value="movie.swf" /> </object>
It’s often a big pain after embedding YouTube (or any other) videos, cos your page will no longer be W3 valid! There are many free online tools to convert youtube embed code to valid xhtml format. You may try this one from tools4noobs. It works great.

IE6 fix for select box over absolute positioned element
On 22, Jul 2009 | One Comment | In Browser, Core JavaScript, IE, JavaScript, jQuery | By abcoder
IE6 sux. General css/javascript hover drop-down menu uses a div or ul with position:absolute. No matter how much you increase the value of z-index the select box (windowed element) will always remain on top most – yes only on a special browser, Internet Explorer 6. The reason is IE6 considers select element as windowed element and keeps it always on top layer.

Solution is using iframe on top of select element, as iframe is also a windowed element placing it on top of select box fix the problem.

Here is the typical HTML code for this drop-down menu:
<div class="top-menus" style="left: 221px; top: 127px;">
<iframe frameborder="0" scrolling="no" align="bottom" marginheight="0" marginwidth="0" src="javascript:'';" style="height: 200px;"></iframe>
<ul>
<li><a href="#">Bracelets</a></li>
<li><a href="#">Rings</a></li>
<li><a href="#">Earrings</a></li>
<li><a href="#">Necklaces</a></li>
</ul>
</div>
The inline css is calculated using jQuery offset() function. FYI, you can easily get the width,height,left,top position of any element using jQuery(“element”).offset(). Make sure the width and height of the iframe is exactly same of it’s overlying UL element. If you apply any border to the UL, you have to consider that during calculating the proper width/height of the iframe.
This is the sample jQuery code:
var timer = null; // global
$("#top-nav a").hover(function(){
clearTimeout(timer);
$("#top-nav a:not('.cur')").removeClass("selected");
$(this).addClass("selected");
var o = $(this).offset();
var left = o.left + 1; // 1px extra for border
var top = o.top + 32; // 32px for placing it just below the horizontal menu
if($(".top-menus").length){
if(left == $(".top-menus").offset().left)
return;
else $(".top-menus").remove();
}
$("body").prepend('<div style="left:'+left+'px;top:'+top+'px;" class="top-menus"><iframe src="javascript:\'\';" marginwidth="0" marginheight="0" align="bottom" scrolling="no" frameborder="0"></iframe><ul>'+html+'</ul></div>');
$(".top-menus").find(".parent, .child").remove();
var hi = $(".top-menus").find("ul").height();
$("iframe").height(hi + 2); // extra 2px for border
}, function(){
clearTimeout(timer);
timer = setTimeout(function(){$("body").find("iframe,.top-menus").remove(); $("#top-nav a:not('.cur')").removeClass("selected");},300);
});
$(".top-menus").live("mouseover",function(){
clearTimeout(timer);
}).live("mouseout",function(){
clearTimeout(timer);
timer = setTimeout(function(){$("body").find("iframe,.top-menus").remove(); $("#top-nav a:not('.cur')").removeClass("selected");},300);
});
I know this code won’t exactly fulfill your requirement, you can get the main idea from this and write your own code yourself. You can see it in action on www.trendtogo.com.
Get Google and Alexa rank of a domain using PHP
On 26, Jun 2009 | 26 Comments | In PHP | By abcoder
There are already a lot of ways to find gpr/alexa rank of a domain using php. But not all of them work on 64bit servers. Here is the code that I always use for finding the google page rank and alexa rank of a website.
Get Google Page rank
function google_page_rank($url) { // URL or domain name
if (strlen(trim($url))>0) {
$_url = eregi("http://",$url)? $url:"http://".$url;
$pagerank = trim(GooglePageRank($_url));
if (empty($pagerank)) $pagerank = 0;
return (int)($pagerank);
}
return 0;
}
function GooglePageRank($url) {
$fp = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /search?client=navclient-auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0 HTTP/1.1\r\n";
$out .= "Host: toolbarqueries.google.com\r\n";
$out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$data = fgets($fp, 128);
$pos = strpos($data, "Rank_");
if($pos === false){} else{
$pagerank = substr($data, $pos + 9);
}
}
fclose($fp);
return $pagerank;
}
}
function StrToNum($Str, $Check, $Magic) {
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648)? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function HashURL($String) {
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) < < 4) | ($Check1 & 0x3C)) << 2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
function CheckHash($Hashnum) {
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0!== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
Find Alexa Rank
function alexaRank($domain){
$remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
$search_for = '<POPULARITY URL';
if ($handle = @fopen($remote_url, "r")) {
while (!feof($handle)) {
$part .= fread($handle, 100);
$pos = strpos($part, $search_for);
if ($pos === false)
continue;
else
break;
}
$part .= fread($handle, 100);
fclose($handle);
}
$str = explode($search_for, $part);
$str = array_shift(explode('"/>', $str[1]));
$str = explode('TEXT="', $str);
return $str[1];
}
Hope this will help you. If you know any better(working) solution please let me know via comments.
Become expert web developer with testking JN0-522 web development course and learn about the latest PHP applications using testking 642-611 tutorials and self paced testking 70-431 study guides.
© Copyright 2012 ABCoder |













Recent Comments