PHP

  • Compare cyrillic letters with PHP

    A few day ago a needed to compare some cyrillic words and letters with PHP. In the example I take last name and check if the last letter is cyrillic “a”. function check_female( $last_name = “Иванова” ){ if(strcmp(mb_substr(($last_name), -1,1,”UTF8″), “а”) == 0){ return 1; }else{ return 0; } }

  • In_array for multidimentional array

    //IN_ARRAY for multidimensional array function in_array_r($needle, $haystack, $strict = false) { foreach ($haystack as $item) { if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) { return true; } } return false; }

  • Currency convertor with PHP

    function currency_convert($amount, $from, $to){ $result = file_get_contents(“https://www.google.com/finance/converter?a=$amount&from=$from&to=$to”); $result = explode(“”,$result); $result = explode(“”,$result[1]); $converted_amount = preg_replace(“/[^0-9\.]/”, null, $result[0]); echo $converted_amount; } currency_convert(1,’gbp’,’usd’);

  • Ajax contact form template

    Ajax contact form template

  • Function for getting random word from words in brackets

    function randomWords($paragraph){ //get one from the words in {} preg_match_all(‘/{(.*?)}/s’, $paragraph, $matches); foreach($matches[1] as $variations){ $variations_array = explode(‘|’,$variations); $paragraph = str_ireplace(‘{‘.$variations.’}’,$variations_array[array_rand($variations_array)],$paragraph); } return $paragraph; } For example {traces | trails | spots}. Will return one of the words in brackets.

  • OpenCart First Things to do!

    Here I prepared some excel file with initial steps for new instalation of OpenCart. These steps will be edited and more will be added later.

  • PHP function for downloading images from http

    This function will download images from another site , resize them and put suffix (if needed). function download_resized_jpeg($filename,$width,$height,$suffix){ $name = explode(‘/’,$filename); $newfilename = end($name); // Content type //header(‘Content-Type: image/jpeg’); list($width_orig, $height_orig, $type) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample…

  • Cross domain access to data on the server PHP

    If you are doing a ajax call to retrieve data from your own server on a platform which is set to prevent these ajax calls . To bypass “Access-Control-Allow-Origin” you need to allow cross domain access by including this in your server php code. header(‘Access-Control-Allow-Origin: *’); OR – for only one domain header(‘Access-Control-Allow-Origin: http//your-domain.com’);…

  • Display Recent Posts outside the WordPress

    How to import recent post from your internal blog to your website without any difficulties. First you need to create wp-latest-blogs.php file where you include wp-load.php for your wp blog.