Short Notes on PHP

From PaskvilWiki
Revision as of 21:13, 1 June 2012 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Convert Accented Characters to Non-Accented

setlocale(LC_ALL, "en_US.utf8");
$translit = iconv("utf-8", "us-ascii//TRANSLIT", $_GET['orig_name']);

Note: On *nix systems, you can check for supported locales using `locale -a`.

Note: Instead of hard-coding the locale to use, you could also use values of HTTP_ACCEPT_LANGUAGE and HTTP_ACCEPT_CHARSET, sent by the browser, to tailor the input locale.

Upload a File using cURL

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="file_box">
    // notice the '@' ahead of the path!
    $post = array(
        "file_box"=>"@/path/to/myfile.jpg",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch);
    // if $response === false, something went wrong
?>