PHP

    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];
    }
    ?>

    How to get emails from the page or string using regular expression

    Here is the code used to extract emails from string or page content
    <?php
    //$string will be simple string or page content

       
    $regx="/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i";            
    preg_match_all($regx, $string, $match);
    // here $match is array returned with all the email ids
    ?>

    How to get first and last day of week ?

    To get First and last day date for week of current month use following code: <?php $week_days = get_month_weekdays(); $first_day_date = $week_days['start']; $end_day_date = $week_days['end']; function get_month_weekdays() { $wk_num = get_current_week_number(time()); $first = 1; $yr = date('Y', time()); $wk_ts = strtotime('+' . $wk_num . ' weeks', strtotime($yr . '0101')); $mon_ts = strtotime('-' . date('w', $wk_ts) + $first .

    How can we use HTML inside PHP ??

    <?php
    while($irow = mysql_fetch_array($iresult, MYSQL_ASSOC))
    {
     
    $image_query = "SELECT image FROM table";
     
    $image_result = mysql_query($image_query);
     
    $image = mysql_fetch_assoc($image_iresult);

      echo
    "<img src='" . $image['image'] . "' name='comm' width='75px' height='60px' id='mainimage' />";
    }
    ?>

    How to Validate string if string is hex in php?

    This can be done in this way:-
    <?php
    $strings
    = array('AB10BC99', 'AR1012', 'ab12bc99');
    foreach (
    $strings as $testcase) {
        if (
    ctype_xdigit($testcase)) {
            echo
    "The string $testcase consists of all hexadecimal digits.\n";
        } else {
            echo
    "The string $testcase does not consist of all hexadecimal digits.\n";
        }
    }
    ?>

    How to write dynamic headers n php?

    you can do in this way:-
    <?php
    header
    ("Content-Type: image/jpeg");
    header('Expires: "' . gmdate("D, d M Y H:i:s",
     
    $expirationDate) . '"');
    imagepng($image, NULL);
    ?>