IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
PHP
DotNET

Unicode to Chinese conversion notes

Unicode expressed like "\u4a44". Chinese words located from 0x3400 to 0x9fa5, including simplified and traditional words. Online tool: Unicode to Chinese covnerter C# Stores unicode data as a string, for each unicode in a string lookup the string by hex or integer number to get the right characters to replace them in the string. string ZHTable = "㐀㐁㐂㐃㐄㐅㐆㐇㐈㐉㐊㐋㐌㐍㐎㐏㐐... ...";   private string GetChar(string unicode) { unicode = unicode.Replace("\\u", ""); var code = Convert.ToInt32(unicode, 16); return ZHTable[code - 13312].ToString(); } var matches = Regex.Matches(text, @"\\u[a-f0-9]{4}"); string result = text; if (matches.Count > 0) { foreach (var m in matches) { var key = m.ToString(); result = result.Replace(key, GetChar(m.ToString())); } }   public string ToChinese(string text) { var matches = Regex.Matches(text, @"\\u[a-f0-9]{4}"); string result = text; if (matches.Count > 0) { foreach (var m in matches) { var key = m.ToString(); result = result.Replace(m.ToString(), GetChar(key)); } } return result; } PHP Stores unicode data in a dictionary like array, for each unicode in a string look up the dictionary to get the right characters to replace them in the string. $unicodedata = [ ... ... 0x3437 => '㐷', 0x3438 => '㐸', 0x3439 => '㐹', 0x343a => '㐺', 0x343b => '㐻', 0x343c => '㐼', ... ... ]; for number calculate as power of 16; for a-f, convert to ascii code - 87, so as a=10, f=15, then calculate as power of 16; for hex letter only has a-f, other than that throw exception. if($this->is_number($u[$i])){ $val += $u[$i] * pow(16, 3-$i); } elseif($this->is_hexletter($u[$i])){ $val += ord($u[$i])-87 * pow(16,3-$i); } to match all unicode, which…

2020-09-18 0 Comments 823 Views 0 Like IT Team Read more
DotNET

String concatenation in c# and php

C# Using + operator Console.WriteLine("Hello" + " " + "String " + "!"); String Interpolation string author = "Mahesh Chand"; string book = "C# Programming"; string bookAuthor = $"{author} is the author of {book}."; String.Concatenate() method string fName = "Mahesh"; string lName = "Chand"; string Name = string.Concat(fName, lName); string[] authors = { "Mahesh Chand ", "Chris Love ", "Dave McCarter ", "Praveen Kumar "}; string arrayStr = string.Concat(authors); String.Join() method int[] intArray = { 1, 3, 5, 7, 9 }; String seperator = ", "; string result = "Int, "; result += String.Join(seperator, intArray); // Using String.Join(String, String[], int int) // Let's concatenate first two strings of the array String[] arr2 = { "Mahesh Chand ", "Chris Love ", "Dave McCarter ", "Praveen Kumar " }; String seperator2 = ", "; string result2 = "First Author, "; result2 += String.Join(seperator2, arr2, 1, 2); Console.WriteLine($"Result: {result2}"); String.Format() method string date = String.Format("Today's date is {0}", DateTime.Now); StringBuilder.Append() method builder.Append(", "); PHP Using . operator $b = "Hello " . "World!"; // slow String Interpolation $a = '3'; echo "qwe{$a}rty"; // double quote echo "Result: " . ($a + 3); // result 6 "{$str1}{$str2}{$str3}"; // one concat = fast   $str1. $str2. $str3;    // two concats = slow //Use double quotes to concat more than two strings instead of multiple '.' operators.  PHP is forced to re-concatenate with every '.' operator. $logMessage = "A {$user->type} with e-mailaddress {$user->email} has performed {$action} on {$subject}." Using printf() $logMessage = sprintf('A %s with email %s has performed %s on %s.', $user->type, $user->email, $action, $subject);    2,762 total views,  10 views today

2020-04-29 0 Comments 1046 Views 0 Like IT Team Read more
PHP

Converting asp.net website to wordpress

Situation Source Version: ASP.NET 4.0 WordPress marketshare has been dramatically increased in recently years. More and more people use WordPress for bloggin or e-commerce applications, and also moving existing site to WordPress to reduce maintenance and SEO cost in the future. Due to ASP.NET and Wordpress are totally different in technology, so converting between them directly is imposible. First try to setup a theme to accommadate the common parts, e.g. header, menu, and footer. Finally I found that it is not easy to find a suitable theme to do this task, and the page contents would be controlled by different set of stylesheet. Give up! Then try second method - the final approach. Key Points Dynamic Resources ASP.NET page contains special hidden dynamic contents: WebResource.axd and ScriptResource.axd files. These are stylesheet and javascripts files that the page rely on during rendering. Common Areas With php we can include files that contains common contents, like header, menu, footer, sidebar. include_once("./includes/header.php"); include_once("./includes/menu.php"); include_once("./includes/footer.php"); Steps Copy the folders that contains static resources to the destination. Open each page source code from browser: right click > view page source. Save the page source to local, name it with php extension. Open WebResource.axd and ScriptResource.axd links from source view, then save them to local. Rename and move to coresponding resouce folders of destination server. Change resource links on page source, remember to change the path based on step 3. Extract common contents and save to separate files with php extension. Replace and include the common contents on each page from the files in step 5.…

2019-11-20 0 Comments 933 Views 0 Like IT Team Read more
PHP

Crawling images from web with PHP

Tool Basic function https://github.com/votinhthuong/crawler_image_php Modification 1. get true image name some sites expose images with query string appended. We need to remove it. add function get_image_name($img_name) to simple_html_dom.php file. //remove image appended chars function get_image_name($img_name){ $exts = Array('jpg','png','gif','ico','webp'); $pos = ''; $imgext = ''; foreach($exts as $ext){ $pos = strpos($img_name, $ext); if(strlen($img_name) - $pos == strlen($ext)) return $img_name; if($pos>0){ $imgext = $ext; break; } } return substr($img_name, 0, $pos).$imgext; } Add one more line of code to get the image name in index.php:   $img_name = get_image_name($img_name); 2. Zip images folder General zip operations open a zip file and add files into it $zip = new ZipArchive; if ($zip->open('test_new.zip', ZipArchive::CREATE) === TRUE){    // Add files to the zip file    $zip->addFile('test.txt');    $zip->addFile('test.pdf');    // Add random.txt file to zip and rename it to newfile.txt    $zip->addFile('random.txt', 'newfile.txt');    // Add a file new.txt file to zip using the text specified    $zip->addFromString('new.txt', 'text to be added to the new.txt file');    // All files are added, so close the zip file.    $zip->close(); } Overwrite an existing zip file $zip = new ZipArchive; if ($zip->open('test_folder.zip', ZipArchive::CREATE) === TRUE) {    // Add files to the zip file inside demo_folder    $zip->addFile('text.txt', 'demo_folder/test.txt');    $zip->addFile('test.pdf', 'demo_folder/test.pdf');    // Add random.txt file to zip and rename it to newfile.txt and store in demo_folder    $zip->addFile('random.txt', 'demo_folder/newfile.txt');    // Add a file demo_folder/new.txt file to zip using the text specified    $zip->addFromString('demo_folder/new.txt', 'text to be added to the new.txt file');    // All files are added, so close the zip file.  …

2018-10-30 0 Comments 790 Views 0 Like IT Team Read more
PHP

PHP - Delete folder

In php, rmdir() is used to delete an empty folder. If the folder has files or sub folders, rmdir command would fail. This deleteDir function would use recursive approach to do the magic. function deleteDir($dirPath) { if (! is_dir($dirPath)) { throw new InvalidArgumentException("$dirPath must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { $deleteDir($file); } else { unlink($file); } } rmdir($dirPath); }  2,062 total views

2018-10-30 0 Comments 783 Views 0 Like IT Team Read more
PHP

Escape JSON Special Characters using PHP

Escape JSON Special Characters using PHP php > 5.2 $str_valid=json_encode($str); php versions older that 5.2 /**  * @param $value  * @return mixed  */ function escapeJsonString($value) { # list from www.json.org: (\b backspace, \f formfeed)     $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");     $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");     $result = str_replace($escapers, $replacements, $value);     return $result; } result {"message":"\\"}  =>  {\"message\":\"\\\\\"} {\"message\":\"\\\\\"} use the json_encode constant JSON_HEX_APOS as the second parameter which will convert all single quotes ' to \u0027. : var t = <?php echo json_encode($data,JSON_HEX_APOS);?>;  3,630 total views,  15 views today

2018-05-22 0 Comments 1098 Views 0 Like IT Team Read more
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
Assign users to a post Uploading multiple files - jquery+php Temporary tables lifetime Extend some useful string functions in C# PHP 7.2 issue - count() CrellySlider - make full width slider
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com