Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to check if url already exists in database in PHP?
  2. $url="http://dev.mysite.com/rahul/palake/?&test=1";
  3.     $parse_url=parse_url($url);
  4.  
  5.     //first check if www is present in url or not
  6.     if(!strstr($parse_url['host'],'www'))
  7.     {
  8.         $scheme=trim($parse_url['scheme']);
  9.  
  10.         //assign default scheme as http if scheme is not defined
  11.         if( $scheme =='')
  12.             $scheme='http';
  13.  
  14.         //create new url with 'www' embeded in it
  15.         $url1=str_replace($scheme."://",$scheme."://www.",$url);
  16.  
  17.         //now $url1 should be like this http://www.mysite.com/rahul/palake/?&test=1
  18.  
  19.     }
  20.  
  21.     //so that $url && $url1 should be considered as one and the same
  22.     //i.e. mysite.com/rahul/palake/?&test=1  is equivalent to  www.mysite.com/rahul/palake/?&test=1
  23.     //should also be equivalent to http://mysite.com/rahul/palake/?&test=1
  24.  
  25.     //code to check url already exists in database goes here
  26.  
  27.     //here I will be checking if table.url like $url or table.url like $url1
  28.     //if record found then return msg as url already exists