It’s a common problem with no single right answer: extract the top domain (e.g. example.com) from a given string, which may or may not be a valid URL. I had need of such functionality recently and found answers around the web lacking. So if you ever “just wanted the domain name” out of a string, give this a shot…

<?php
function get_top_domain($url, $remove_subdomains = 'all') {
  $host = strtolower(parse_url($url, PHP_URL_HOST));
  if ($host == '') $host = $url;
  switch ($remove_subdomains) {
    case 'www':
      if (strpos($host, 'www.') === 0) {
        $host = substr($host, 4);
      }
      return $host;
    case 'all':
    default:
      if (substr_count($host, '.') > 1) {
        preg_match("/^.+\.([a-z0-9\.\-]+\.[a-z]{2,4})$/", $host, $host);
        if (isset($host[1])) {
          return $host[1];
        } else {
          // not a valid domain
          return false;
        }
      } else {
        return $host;
      }
    break;
  }
}// some examples
var_dump(get_top_domain('http://www.validurl.example.com/directory', 'all'));
var_dump(get_top_domain('http://www.validurl.example.com/directory', 'www'));
var_dump(get_top_domain('domain-string.example.com', 'all'));
var_dump(get_top_domain('domain-string.example.com/nowfails', 'all'));
var_dump(get_top_domain('finds the domain url.example.com', 'all'));
var_dump(get_top_domain('12.34.56.78', 'all'));
?>

Most of the examples are simply proofs, but I want to draw attention to the string in example #4, 'domain-string.example.com/nowfails'. This is not a valid URL, so the call to parse_url() fails, forcing the script to use the entire original string. In turn, the path part of the string causes the regex to break, causing a complete failout (return false;).

Is there a way to account for this? Surely, however I’m not about to tap that massive keg of exceptions (i.e. just a slash, slash plus path, slash plus another domain in a human-readable string, etc).

No regex for validating URL’s or email addresses is ever perfect; the “strict” RFC requirements are too damn broad. So I did what I always do: chose “what works” over “what’s technically right.” This one requires any 2-4 characters for a the top level domain (TLD), so it doesn’t allow for the .museum TLD, and doesn’t check to see if the provided TLD is actually valid. If you need to do further verification, that’s on you. Here’s the current full list of valid TLD’s provided by the IANA.

If you need to modify the regex at all, I highly recommend you read this article about email address regex first for two reasons:

  1. There’s a ton of overlap between email and URL regex matching
  2. It will point out all the gotcha’s in your “better” regex theory that you didn’t think about

Recently,  I went through a weird problem when i try to update my friends Nokia 5800 Music Express via Nokia Software Updater Application. The message that i got in the Nokia Software Updater application is below.

 

Steps to solve this problem :

  1. Go to Control Panel > Administrative Tools > Services.
  2. Find services “Internet Connection Sharing” and “Windows Firewall”
  3. Stop both services then start Nokia Software Updater.

 

Cheers   🙂  !!!

 

Apple‘s CEO Steve Jobs is ranked as the world’s 110th richest person with net worth of $8.3 billion according to Forbes annual list. Last year, Jobs’ net worth was up from $5.5 billion and 136th place so I think he made a great milestone in one year.



It’d be interesting if we take a look at Facebook‘s Mark Zuckerberg wealth which is with net worth of $13.5 billion. Zuckerberg is ranked as the 52nd richest person in the world.

DAVOS-KLOSTERS/SWITZERLAND, 30JAN09 - Mark Zuc...

Image via Wikipedia

Image representing Steve Jobs as depicted in C...

Image via CrunchBase

 

For those who wants to know more, Mexican telecommunications tycoon Carlos Slim Helu holds the top spot in the list followed by Microsoft founder Bill gates with net worth of $74 billion and $56 billion respectively.

Firefox 4 RC is out!

Posted: March 11, 2011 in News
Tags: ,
Mozilla Firefox word mark. Guestimated clear s...

Image via Wikipedia

 

 

 

The wait is over … Firefox 4 Release Candidate (RC) is available for download for Windows, Mac and Linux.

 

 

 

Here’s the official announcement:

Mozilla Firefox 4 for Windows, Mac and Linux has exited the beta cycle and is now available as a release candidate in more than 70 languages. The millions of users testing Firefox 4 will be automatically updated to this version and will join our Mozilla QA team in validating the new features, enhanced performance and stability and HTML5 capabilities in Firefox 4. Testers are encouraged to check out the Web O’ Wonder in order to see the future of the Web with cutting edge demos that showcase the incredible online experiences developers can now create and users can experience. Developers can submit their own demos to the Mozilla Developer Network Demo Studio.

The important stuff from the release notes:

This Firefox 4 RC is considered to be stable and safe to use for daily web browsing, though the features and content may change before the final product release. At this time many Add-ons may not yet have been tested by their authors to ensure that they are compatible with this release. If you wish to help test Add-on compatibility, please install the Add-on Compatibility Reporter – your favorite Add-on author will appreciate it!

Download available here.

Release notes here.

Changelist here.

Inernet Explorer 9 RC (Release Candidate) was released on 10th February, now Microsoft is ready to release the final version RTM of Internet Explorer 9 on 14th March at the SXSW conference.

Microsoft has alre

Internet Explorer 9

Image via Wikipedia

ady said that Internet Explorer 9 RC will automatically update to the Final version of IE9 (internet Explorer 9). But now it’s unsure whether Microsoft will provide this update on 14th March at the SXSW conference or if we’ll have to wait for the next Patch Tuesday. In either case direct download should be available around 9pm on 14th March.

On the other hand Microsoft Developer Network India, has tweeted that final Version of Internet Explorer 9 RTM will release on 24th March at Tech.Ed in India.
Microsoft might launch Internet Explorer 9 on 14th march and may officially launch it in India on 24th March. So Internet Explorer 9 Final version RTM is expected to release on 14th March, but is confirmed for Release on 24th March.

I Just went through a problem on my friends laptop it has windows XP. He wanted to enable “Use Fast User Switching”.  But it gave a strange alert saying “client services for netware has disabled the welcome screen and fast user switching” to disable the “netware”.

Lets see what is netware ?

NetWare is a network operating system (NOS) that provides transparent remote file access and numerous other distributed network services, including printer sharing and support for various applications such as e-mail transfer and database access.

Fix:

To enable welcome screen login, you need to disable the netware client services.

Follow the steps below to disable Netware client services:

How to disable netware client services?

1. Go to Control Panel > Network Connection . This will open up the network connections available on your computer.

2. Right click on the connection and select Properties.

3. In general tab, uncheck the option for Client Services for NetWare and press OK.
As shown in the picture below.

4. Repeat step 2 and 3 for all the connections shown in network connections.

5. Restart your computer.

6. To enable welcome screen now, go to Control Panel > User Accounts > Change the way users login and select the option Use Welcome Screen. We hope following the above procedure you will be able to fix the trouble.

Released in 2001, Internet Explorer 6 has been one of the most frustrating browsers ever released. Since it doesn’t support a lot of key web standards, a high percentage of websites look awful on IE6, to a level where it makes the site almost unreadable.

Unfortunately, the browser is still used by millions of people around the world, therefore a large number of high profile people and companies support projects such as IE 6 No More and Bring Down IE6.

Today I would like to show you a range of WordPress plugins which force or encourage visitors to upgrade their browser if they are using Internet Explorer 6. It may sound like a drastic step however it’s worth doing if your design doesn’t work on IE 6 (unfortunately many top designs are). Most of these plugins work in a similar way so I recommend trying a few in your test area and choosing which one suits you.

I hope you’ve found this article useful.

Best of luck :)

To open a new window using javascript can use the following function. You just have to do is send the link and the window name.

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == ‘string’)
href=mylink;
else
href=mylink.href;
window.open(href, windowname, ‘width=800,height=800,scrollbars=yes’);
return false;
}

The non-DOM property innerHTML can’t add options to a tag select in Internet Explorer.

Example not working:

document.getElementById("my_select").innerHTML 
= "<option value='1'>not</option> 
<option value='2'>work</option>"; 

The correct way to insert options in a select is using appendChild or addOption functions. But that’s tiring if we are working with Ajax.

Use innerHTML is not the standard but it is very useful.

The function above, will help you to insert options like using innerHTML, in IE, Firefox or Opera.

Updated: now supports option-selected

Using my function:

var inner = 
"<option value='1'>Now</option> 
<option value='2'>work</option>"; 


select_innerHTML(document.getElementById("my_select"),inner);

The function. Add to your lib.

function select_innerHTML(objeto,innerHTML){

    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().
replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
opt.setAttributeNode(spantemp.attributes[j]
.cloneNode(true));


     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

Sometimes you get those errors that just pick at you and you can’t seem to find a solution. It happened to me this morning when testing a JavaScript library I’m writing in IE7. FireFox worked without a hitch, but IE threw an ‘expected identifier, string or number’ error pointing to the last line of the variable declaration. Of course it didn’t help that my copy of MS Script Debugger wanted to lock up my computer.

 

Here’s a very shortened example of the code I was working on.

JavaScript:

  1. var variableName =
  2. {
  3. function1:   function()
  4. {
  5. //  Do something
  6. },
  7. function2:   function()
  8. {
  9. //  Do something else
  10. },
  11. variable1:    ‘Some value’,
  12. variable2:    ‘Another value’,
  13. };

The error was reporting a problem on line 13. So after hacking my way around trying to figure out why it was giving me this error, I went out Googling. About 10 pages into the search results I found the solution.

Look at line 12. See the comma after ‘Another value’? That’s what was causing the error. I had taken out a variable under that one but forgot to remove the comma. FireFox ignored the error, but not IE.

One little misplaced character, so much wasted time. Hopefully y’all will spend less time finding the fix than I did.