PHP

    How to setup phpmyadmin on website

    To setup phpmyadmin on site upload phpmyadmin from any wamp installation found in www/app directory or you can download phpmyadmin from http://www.phpmyadmin.net/home_page/downloads.php After uploading create config.inc.php from config.sample.inc.php and go to the directory http://www.mohitsharma.net/phpmyadmin/ like this you will be prompted for username and password in this case
    $cfg['Servers'][$i]['auth_type']     = 'cookie';
    if you have to access directly you can add auth_type as
    $cfg['Servers'][$i]['auth_type']     = 'config';
    and add the

    mysql_fetch_array(): supplied argument is not a valid MySQL result resource solved

    To solve the problem of mysql_fetch_array(): supplied argument is not a valid MySQL result resource You can use query like this no resource error then
    <?php

    $count_query
    = @mysql_query("select pid from portfolio where category=". $cid);
    $pids = array();
    if (
    $count_query) {
      while (
    $count_result = @mysql_fetch_array($count_query)) {
       
    $pids[] = $count_result['pid'];
      }
    }
    ?>

    How to remove special characters from string using php?

    To remove special characters from string use preg_replace like this
    <?php
      $mydata
    = 'this is @ test & Strings';

     
    $mydata = preg_replace("/[^a-zA-Z0-9s]/", "", $mydata);

     
    //print $mydata; will output "thisistestStrings"
    ?>

    How to highlight keywords in search results in php

    You can use the below code with the css to highlight keywords in the search results
    Css Styles:
    <style type="text/css">
    .search_highlight {
      background-color:#ffffcc;
    }

    PHP Code to highlight search results
    <?php
    $keywords
    = <SEARCH KEYWORD>; //Keyword to highlight.
    $searchresults = <RETURNED STRING>; //Result of search.
    preg_replace("|($keywords)|Ui", "<span class='search_highlight'>$1</span>", $searchresults);
    ?>

    How to detect browser using php

    To detect browser in php follow the steps:
    1. Download the class file Click Here
    2. Create Browser class object and call getBrowser() function.

    <?php
    include 'Browser.php';
    $getbrowser= new Browser();
    $browser_name = $getbrowser->getBrowser();
    $browser_version = $browser->getVersion();

    //You can use $browser_name and $browser_version in conditions to excute code in specific browsers
    ?>

    How to increment decrement date in php

    To increment/decrement date in php you can use simple process as follows: <?php $your_date = '2011-05-20'; //You need to increment it by 2 day //Convert to time stamp first $your_date_ts = strtotime($your_date); //Increment By 2 Day $your_date_dt = strtotime('+2 day', $your_date_ts); echo date('Y-m-d', $your_date_dt); //Increment By 2 Week $your_date_tw = strtotime('+2 week', $your_date_ts); echo date('Y-m-d', $your_date_tw); //Similar process is followed for decrement just user -2 day or -2 week in place of +1 day or +1 week //Decrement By 2 Day

    How to create download link in php?

    You can create download link in many ways one of the way is as below: Create a file download.php like below <?php // The file path where the file exists $filepath = "http://mohitsharma.net/downloads/".$_GET['filename'].""; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //setting content type of page header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".basename($filepath )); header("Content-Description: File Transfer"); /

    How do we remove element from array?

    You Can use this function to do so
    <?php
    function remove_element($arr_content,$arr_value) {

       return
    array_values(array_diff($arr_content, array($arr_value)));

    }
    ?>

    How to get domain from path ?

    Use the following code
    <?php
    $domain
    = fetch_domain_name('http://www.facebook.com');
    print
    $domain; //it will output "facebook"
    function fetch_domain_name($path){
       
    $check = preg_match("/(.*:\/\/)\w{0,}(.*)\.(.*)/", $path, $output);
       
    $output[2] = str_replace(".","",$output[2]);
        return
    $output[2];
    }
    ?>