Posted by & filed under JSON, PHP.

To convert a JSON array into a PHP array, use the following script:

<?php
$json = file_get_contents('json/yourscript.json'); // Get the JSON data
$phpObj = json_decode($json,true);  // Convert to PHP Object
print_r($phpObj);  // Convert to PHP Array
?>

file_get_contents('json/yourscript.json'); Allows you to get the JSON data easily.

json_decode($json,true); Is a PHP function that converts your JSON data into a PHP Object.

print_r(); Will change the PHP object into a PHP readable array.

Posted by & filed under HTML, Javascript, jQuery, Website Development.

Whenever I want to quickly make a webpage, I don’t want to have to build the whole page everytime. Here is my starter code for an HTML5 page. The key points are :

  • HTML5 Doctype – Ready
  • Viewport and Mobile – Ready
  • Title tags, Character Set, Keyword and Description Meta, Favicon, Stylesheet tags – Ready
  • Google Font – Ready
  • Javascript and jQuery – Ready
  • jQuery CDN for lastest version of jQuery – Ready
  • HTML5 Shiv for IE9 and less – Ready
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>HTML Starter Template</title>

<meta name="keywords" content="HTML5,quickstart,template">
<meta name="description" content="HTML5 Quickstart Template">
<meta name="author" content="GetPowers Coding">

<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/quickstyle.css">
<style>

/* Your CSS3 styling here */

</style>

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>

<!--- Observable Content Here --> 

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){

/* Javascript and jQuery here */

});
</script>

</body>
</html>

It’s useful to have some quick CSS, but not something bloated. Here is my CSS template as well. I set the width to 90% so that it will quickly work on mobile or full screen.

/* quickstyle.css */

body {
width:90%;
margin:10px auto;
font-family:'Open Sans',verdana,arial;
font-size:14px;
color:#111;
background-color:#fff;
}

If you want to make your site feel more like a web application. Try adding the following:

<meta name="apple-mobile-web-app-title" content="DriversTestInfo">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<link rel="apple-touch-startup-image" href="/startup-image.png">

<link rel="apple-touch-icon" href="apple-touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="76x76" href="touch-icon-ipad.png"> 
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png"> 
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png"> 
<link rel="icon" sizes="196x196" href="nice-highres.png">
<link rel="icon" sizes="128x128" href="niceicon.png"> 

For Chrome and iOS web application details try the following:
https://developer.chrome.com/multidevice/android/installtohomescreen#comparison-to-ios
https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
http://blog.teamtreehouse.com/optimizing-mobile-web-apps-ios
https://gist.github.com/tfausak/2222823

Posted by & filed under Website Development.

I used to try to get substrings of Chinese text and would get partial characters than came out as strange diamonds or squares…. until I found the mb_strcut() function!

When using PHP, avoid using the substr() function, as it will often cut off Chinese and Japanese characters. For example:

$text = '拿小锤锤的那个人好可爱的说,哈哈哈,生活太有爱了,加油加油了';

echo  substr($text, 0, 50); // Outputs: 拿小锤锤的那个人好可爱的说,哈哈��

Rather you should use the mb_strcut() function.

For example:

<?php
$text = '拿小锤锤的那个人好可爱的说,哈哈哈,生活太有爱了,加油加油了';

echo mb_strcut($text, 0, 50,'UTF-8'); // Outputs: 拿小锤锤的那个人好可爱的说,哈哈

echo  mb_strcut($text, 15, 30,'UTF-8'); // Outputs: 那个人好可爱的说,哈
?>

Posted by & filed under Applications, Development.

Kapianyingyu.com, is built to help Chinese speakers learn English and Japanese vocabulary quickly and conveniently. It’s designed to work on a full-screen desktop computer and mobile devices.

It has a database over 4000 everyday English words and 140 useful categories. A card page consists of a small quiz, where the user must choose the correct word that matches the card. Next the user can hear the proper pronunciation of the word, as well as Japanese and Chinese. The user can also see example sentences and definitions.

Check out Kapianyingyu.com

Posted by & filed under Applications, Development.

We are excited to introduce a Chinese version of our Storyways.com website called Gushijielong.net (Chinese:故事接龙网). This new website offers the same great user experience as Storyways.com in Chinese.

Both Gushijielong.net and Storyways.com allow users to go through a Choose Your Own Adventure story but when they reach the end, they have the chance to write the next part of the story. The story then can extend and grow much farther than a typical Choose Your Own Adventure.

We invite our Chinese friends to try Gushijielong.net

gushijielong-284x300

Posted by & filed under Applications, Development.

Looking for a Choose Your Own Adventure book with a twist? Check out Storyways.com, the new online community story building site. On Storyways.com, you choose a story and start your adventure. Each page gives you a piece of the story and you decide which direction to take. The exciting twist is that when you get to the end of the story, you’ll have the chance to add to the story! The site is moderated and stories are checked for quality and to keep it fun for all. The site also can be accessed on tablets and smartphones so you can take the adventure with you!

Storyways.com

The Chinese version can be found at Gushijielong.net

Posted by & filed under Development.

disqus-150x150

Recently we’ve added commenting to our Driverstest.info license test question and quiz website. We used a third party comment platform provider called Disqus.com. Our goal was to add commenting but not increase the load time for our users. Fortunately, thanks to Paul Underwood’s article about adding Disqus with AJAX, we’ve added this great feature without increasing load time.

Some great features about Disqus are that users can comment without having to build our own commenting system. The system is flexible to work on mobile, tablets, or fullscreen without additional markup. Users can use with facebook, google+, twitter. Finally, it offers an easy way to moderate. We’ll test it out over the coming weeks, but we think its probably a go.

Posted by & filed under PHP.

$_SERVER['HTTP_REFERER'] gives you the URL from where the user came, which is the user’s previous page (whatever page that would appear if the user clicked “Back” in their browser)

But $_SERVER['HTTP_REFERER']  gives you the complete URL, something like this :

driverstest.info/test/quiz.php?quizgroup=7

If you just want get the domain name .i.e. driverstest.info from the full URL, then you can use the following code:

$referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);

Note though that the referer is easy to spoof, so it’s not reliable.

Posted by & filed under PHP.

Here is a lovely bit of code to help you convert months in numbers to proper names!

<?php
 $monthNum = 11;
 $monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
 echo $monthName; // Outputs: November
 ?>