Friday, October 14, 2011

How to find the common values of two array, without using array_intersect


$array1 = array(’3′,’8′,’7′,’2′);
$array2 = array(’4′,’5′,’7′,’2′);
$length1=count($array1);
$length2=count($array2);
$common=array();
if ($length1 > $length2)
{
for ($i=0; $i<$length1; $i++)
{
if (in_array($array1[$i], $array2))
{
$common[]=$array1[$i];
}
}
}
else
{
for($i=0; $i<$length2; $i++)
{
if (in_array($array2[$i], $array1))
{
$common[]=$array2[$i];
}
}
}
print ‘
’;

print_r($common);
?>

category sub category program


mysql_connect("localhost","root","");
mysql_select_db("test");
class Categories
{
public function categories_tree($country_id='',$parent='0',$spacer='')
{
$sql = mysql_query("SELECT * FROM categories WHERE parent='$parent'");
$num = mysql_num_rows($sql);
$spacer .= '- ';
while ($row = mysql_fetch_array($sql))
{
if ($num == 0 || $row['parent']=='0')
{
$spacer = '';
}
echo $spacer.'‘.$row['name'].’
‘;
$this->categories_tree($country_id, $row['id'], $spacer);
}
}
}
$cat = new Categories();
$a = ”;
echo $cat->categories_tree(0, $a);
?>

Monday, September 19, 2011


Curl Example

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.h3webdev.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer))
{
    print "Sorry, example.com are a bunch of poopy-heads.
";
}
else
{
    print $buffer;
}

Friday, April 1, 2011

Regular expression for replace special character from an string

$output = preg_replace("/[^A-Za-z0-9]/","",$string_user);

Tuesday, March 29, 2011

When to use InnoDB?


InnoDB uses row level locking, has commit, rollback, and crash-recovery capabilities to protect user data. It supports transaction and fault tolerance.


When to use MyISAM?


MyISAM is designed with the idea that your database is queried far more than its updated and as a result it performs very fast read operations. If your read to write(insert|update) ratio is less than 15% its better to use MyISAM.

MyISAM Or InnoDB MySQL engine?


MyISAM limitations

No Foriegn keys and cascading deletes and updates
No rollback abilities
No transactional integrity (ACID compliance)
Row limit of 4,284,867,296 rows
Maximum of 64 indexes per row


InnoDB Limitations

No full text indexing
Cannot be compressed for fast, read-only

Monday, March 28, 2011

Generate Random 10 digit String


function genRandomString($length) {
    //$length = 10;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';  
    for ($p = 0; $p < $length; $p++)
{
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

   echo strtoupper(genRandomString(10));

Generates a random string of variable length


function getUniqueCode($length = "")

  {

   $code = md5(uniqid(rand(), true));

   if ($length != "") return substr($code, 0, $length);

   else return $code;

  }

Thursday, March 24, 2011

Google Refferal Code


function search_engine_query_string($url = false)
{
    if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
        return '';
    }
    $parts_url = parse_url($url);
    $query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
    if(!$query) {
        return '';
    }
    parse_str($query, $parts_query);
    $res = isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
  if($res)
{
preg_match("/[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))/", $res, $matches);
return $matches[0];
}
return false;
}

Read a page's GET URL variables and return them as an associative array.


function getUrlVars()
 {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

  for(var i = 0; i < hashes.length; i++)
  {
   hash = hashes[i].split('=');
   vars.push(hash[0]);
   vars[hash[0]] = hash[1];
  }

  return vars;
 }


Make Tab Dynamically Active Using JQuery and PHP

   // Some condition According to this assign valoues of $tab_act as 0, 1, 2
  // First Condition
  if(!empty($_GET)){
    $tab_act = 1;
  }else{
     $tab_act = 0;
  }
// Second Condition if Values are come through url make it an array
$name = explode('/',$_SERVER['REQUEST_URI']);
$name_url = $name['1'];
if($name_url == ''){
   $tab_act = 0;
} else{
   $tab_act = 1;
}
// Note :- Use Condition According to your requirement and assign values in $tab_act = 0;
?>

$(document).ready(function() {

//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:eq()").addClass("active").show(); //Activate first tab
$(".tab_content:eq()").show(); //Show first tab content

//On Click Event
$("ul.tabs li").click(function() {

$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});

Wednesday, March 23, 2011

Extract Email Address From Search URL ( Different Search Engine )in PHP

function search_engine_query_string($url = false) {

if(!$url) {
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
}
if($url == false) {
return '';
}

$parts = parse_url($url);
parse_str($parts['query'], $query);

$search_engines = array(
'bing' => 'q',
'google' => 'q',
'yahoo' => 'p'
);

preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);

return isset($matches[1]) && isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';

}
?>

$url = "http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=test+hanzala+test%40test.com+worpres&aq=f&aqi=&aql=&oq=";

$url_bing = "http://www.bing.com/search?q=Hanzala+Subhani+h.subhani%40live.com&go=&form=QBRE&filt=all&qs=n&sk=";

$url_yahoo = "http://in.search.yahoo.com/search;_ylt=A8pWB9pHxYlNdhMAUvy7HAx.;_ylc=X1MDMjExNDcyMzAwMwRfcgMyBGFvAzEEZnIDeWZwLXQtNzA0BGhvc3RwdmlkA0JDSzd6M2xsbWs4RkpXc0tUWHRhMVFjSmVEaXhCMDJKeFVjQUFGMlAEbl9ncHMDMARuX3ZwcwMxNgRvcmlnaW4Dc3JwBHF1ZXJ5A2hhbnphbGEgaC5zdWJoYW5pQGxpdmUuY29tBHNhbwMxBHZ0ZXN0aWQDU01FSU4wMQ--?p=hanzala+h.subhani%40live.com&fr2=sb-top&fr=yfp-t-704&rd=r1";
//$url = "http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=test+hanzala+worpres&aq=f&aqi=&aql=&oq=";
$search_url="";
echo "Res=".$search_url = search_engine_query_string($url_yahoo);
echo "
";


   preg_match("/[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))/", $search_url, $matches);
  echo $matches[0];
?>

Function for Extract Search String From Search URL ( Different Search Engine )in PHP

function search_engine_query_string($url = false) {

if(!$url) {
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
}
if($url == false) {
return '';
}

$parts = parse_url($url);
parse_str($parts['query'], $query);

$search_engines = array(
'bing' => 'q',
'google' => 'q',
'yahoo' => 'p'
);

preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);

return isset($matches[1]) && isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';

}

Monday, March 21, 2011

Show All monthly Archive in Wordpress

Please follow the step

write the following code just above
while ( have_posts() ) : the_post();
loop

$name = explode('/',$_SERVER['REQUEST_URI']);
$year = $name[1];
$month = $name[2];
$args = array(
'posts_per_page' => -1,
'year' => $year,
'monthnum' => $month,
'order' => 'ASC'
);
query_posts( $args );



Function Used to get splitted URL
$name = explode('/',$_SERVER['REQUEST_URI']);

Monday, March 7, 2011

Saturday, February 26, 2011

List files in directory and sub directories

$file){
foreach (ListFiles('.') as $key=>$file)
{
echo $file ."
";
}
?>

Monday, January 24, 2011

Difference Between GET and POST methods

S. NO GET POST
 1 Data is appended to the URL. Data is appended to the URL. 
2 Data is not secret. 

Data is Secret 

3 It is a single call system 

It is a two call system. 

4 Maximum data that can be sent is 256. 

There is no Limit on the amount of data.That is characters any amount of data can be sent. 

5 Data transmission is faster 

Data transmission is comparatively slow. 

6 This is the default method for many browsers 

No default and should be Explicitly specified.

OS Commerce

osCommerce is a popular Open Source online shop e-commerce solution that is powered by a dedicated, strong, and ever growing community, and is released under the GNU General Public License.
Everything you need to get started in selling physical and digital goods over the internet, from the Catalog frontend that is presented to your customers, to the Administration Tool backend that completely handles your products, customers, orders, and online store data.


Source 


http://www.oscommerce.com/

Thursday, January 20, 2011

require() and require_once():

require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING.

There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().

require() and include()

require() and include() are identical in every way except how they handle failure.
include() produces a Warning while require() results in a Fatal Error.
In other words, don’t hesitate to use require() if you want a missing file to
 halt processing of the page. include() does not behave this way,
the script will continue regardless. Be sure to have an appropriate
include_path setting as well.

* require() : If the file does not exist, you will get a fatal error.
* include() : If the file does not exist, you will get a warning and the next line of code will execute.


Second Highest Salary

select min(sal) from emp where sal=(select sal from emp where sal<>MIN(SAL) )          
OR
from emp where sal=(select sal from emp having sal<>MIN(SAL)

select min(sal) from emp where sal>(select max(sal) from emp );

SELECT * FROM ( SELECT rownum n id salary FROM (select id salary from employees order by salary )) where n = 2 select min(sal) from emp where sal=(select sal from emp having sal<>MIN(SAL) )

SELECT min(sal) FROM emp WHERE sal > (SELECT Min(sal) FROM emp)

Friday, January 14, 2011

How To insert image into Database.

Please follow the below Steps:-

(1) Create a database

   CREATE TABLE IF NOT EXISTS `image_upload` (
  `image_upload_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(222) NOT NULL,
  `image` varchar(222) NOT NULL,
  PRIMARY KEY (`image_upload_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
(2) create a folder structure inside your web application folder.

     images/company

(3) Create a file upload_image.php

     (a) create HTML form using two field name as user_name,image

    (b) inside the form tag use attribute enctype="multipart/form-data".

    (c) and finally use the following code for inserting values.

      
          $connection = mysql_connect("localhost","root","");
         mysql_select_db("hanzala_test",$connection);
      ?>



if(!empty($_POST))
{
   $user_name = $_POST['user_name'];

   if(isset($_FILES['image']['name']) && $_FILES['image']['name']!='')
   {
$desired_path = 'images/company/';

$rand=rand(0,999);
$desired_file_name = $rand.'_'.str_replace(' ','_',strtolower($_FILES['image']['name']));

move_uploaded_file($_FILES['image']['tmp_name'], $desired_path . $desired_file_name);
}

$query_insert = "INSERT INTO image_upload SET
user_name = '".$user_name."',
image = '".$desired_file_name."'

";
mysql_query($query_insert);

header("location:upload_image.php");exit;
}

?>


For Further Assistance Please Contact to me