Following it a simple code snippet with uses JSON (Javascript Object Notation) to fetch the Bible Verse of the Day from biblegateway.com .
The PHP Script
<?php
$fp = file_get_contents("http://www.biblegateway.com/votd/get?format=json&version=31");
/* Used to get the contents in JSON format */
$obj = json_decode($fp); /* This function comes built from php 5.2.x versions. This will decode the JSON to Object Format */
echo "<div style='padding-right:15px; padding-left:15px; margin-right:10px;color:#371700;font-family:Arial,Helvetica,sans-serif;font-size:13px;'>";
echo $obj->votd->text."<br><strong>"; /* This value Contains the Bible Text */
echo $obj->votd->reference."</strong>"; /* This Contains the reference text */
echo "</div>"
?>
Continue reading →
Posted in PHP
|
Tagged JSON, PHP
|
Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. If you are runing LINUX machine, goto ‘/usr/bin/‘
Shell Commands
# Goto cd /usr/bin/
export EDITOR=vi ; # Select the editor
crontab -l - # List all Crontab entries
crontab -e - # Edit the Crontab file
crontab -r # Remove your crontab file
crontab -v # Display the last time you edited your crontab file.
Posted in Linux
|
Tagged cronjob, crontab, Linux, PHP
|
Simply we can convert PO(portable Object) to MO(Machine Object) Using Poedit or from the GNU gettext msgfmt command.( see the installation of gettext ). Or you can check for the UI application on the same functions. Click Here
Shell Commands
msgfmt -c -v -o out_message.mo input_message.po
# ############### Options are ###########
# -c option does detailed checking of the PO file format.
#
# -v makes the program verbose.
#
# -o option output filename.
# ###################################
To extract the strings to be translated from the program source code. This is achieved with xgettext. I think you are much familiar with gettext method for the internationalization. If you wish to get more information about the internationalization with GNU gettext method, click here. You will get the complete gettext functionality by installing/extracting the package from the following urls.
http://www.gnu.org/software/gettext/
http://gnuwin32.sourceforge.net/packages/gettext.htm
Download the latest release from the link and extract to you machine. And execute the following commands.
Note: In my example, the package path is C:GnuWin32bin and the source file are int C:source_file Openup the Command Prompt and move to the bin folder.
Suppose my PHP source file contents are as like this:
Continue reading →
This is_utf8() function is to detect UTF-8 strings, and return a boolean value. The for loop is to go through all bytes in $str. ord gets the decimal number of the current byte. If the number if less than 128 (0×80), it’s a single byte character. If it’s equal or larger than 128, the length of the multi-byte character is checked. That can by done with the first character of a multi-byte character sequence. If the first byte begins with 110xxxxx, it’s a two byte character; 1110xxxx, it’s a three byte character, etc.
The PHP Script
<?php
function is_utf8($str) {
// get length, for utf8 this means bytes and not characters
$len = strlen($str);
// we need to check each byte in the string
for ($i=0; $i < $len; $i++) {
// get the byte code 0-255 of the i-th byte
$c = ord($str[$i]);
if ($c < 0x80) $bits = 0; // 0bbbbbbb
elseif (($c & 0xE0) == 0xC0) $bits = 1; // 110bbbbb
elseif (($c & 0xF0) == 0xE0) $bits = 2; // 1110bbbb
elseif (($c & 0xF8) == 0xF0) $bits = 3; // 11110bbb
elseif (($c & 0xFC) == 0xF8) $bits = 4; // 111110bb
elseif (($c & 0xFE) == 0xFC) $bits = 5; // 1111110b
else return false; // Does not match any model
for ($j=0; $j<$bits; $j++) { // n bytes matching 10bbbbbb follow ?
if ((++$i == $len) || ((ord($str[$i]) & 0xC0) != 0x80))
return false;
}
}
return true;
}
?>
Continue reading →
Posted in PHP
|
Tagged encoding, PHP, String, utf-8
|