Top PHP Frameworks

Info.Tech, PHP, Web Development Comments Off on Top PHP Frameworks
Top 5 PHP Frameworks Infographic
From: www.zfort.com

[Solution] JpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.

Info.Tech, PHP, Web Development Comments Off on [Solution] JpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.

JPGRAPH

I always stumble down with this error for couple of projects now.

JpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.

Two solutions as I know:

  1. install the required library
  2. or simply comment certain line

 

For solution #1, simply cast yum install php-gd.

For solution #2, as of version 3.5.0b1 — comment line 110 (function SetAntiAliasing) at file gd_image.inc.php

and that’s it… problem solved.

Another issue will be fonts:

JpGraph Error: 25049 Font file "/usr/share/fonts/truetype/arialbd.ttf" is not readable or does not exist.

Look for jpg-config.inc.php and add these lines:

define('CACHE_DIR','cache/');
define('TTF_DIR','includes/jpgraph/fonts/');

Note: Just place the right path where you setup your jpgraph folder

Download required JpGraph Fonts: JpGraph Fonts (1335)

And that should solve the problems… 🙂

Samples:

progression_graph_1386128392 progression_graph_1386188039

IDE: NetBeans vs phpStorm

Info.Tech, PHP, Web Development Comments Off on IDE: NetBeans vs phpStorm

Before back in college, I used UltraEdit, then Notepad++ as my HTML JS, CSS and PHP editor. I even tried Dreamweaver and it sucks for me. I also tried Ecplise and its way heavy application, too slow to load.

I’ve been using NetBeans IDE for a while now. I met a PHP programmer and mention about phpStorm and got curious. So I downloaded phpStorm 7.0 and tested it out myself. I still find NetBeans as the Best IDE. Though I like the UI of phpStorm, I find it so COOL (see screenshot below) but (geeezz!) its too pricy will cost you $99 for personal license. Loading performance, I still voted for NetBeans. Features like FTP, SSH, Git, SVN etc — most likely they have both NetBeans and phpStorm.

netbeans_vs_phpstorm

 I guess, I felt the same with other PHP developers about NetBeans, phpStorm, Eclipse and other IDEs. See: http://www.warriorforum.com/programming-talk/637270-eclipse-vs-netbeans-vs-phpstorm.html

PHP and MySQL TimeZone Synchronization

Info.Tech, PHP, SQL: Structured Query Language, Web Development Comments Off on PHP and MySQL TimeZone Synchronization

We all know the PHP and MySQL holds different timezone… what if we want both PHP and MySQL sync together by adjusting your PHP code only…

Here’s the solution:

<?php

define('TIMEZONE', 'Australia/Brisbane');

@date_default_timezone_set(TIMEZONE);

$dt = new DateTime();

// get time offset
$offset = $dt->format("P"); 

// update mysql timezone
mysql_query("SET time_zone='$offset';");

?>

 

Thanks to Craig Buckler…

Reference: http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/

PHP + Firebird SQL Installation

Info.Tech, PHP, SQL: Structured Query Language, Web Development Comments Off on PHP + Firebird SQL Installation

Download the following: (In my case, it’s 64bit)

  1. PHP
  2. Apache
  3. Firebird (http://www.firebirdsql.org/en/firebird-2-5-2-upd1/)

After installation of PHP, edit the php.ini and uncomment:

  • php_interbase.dll
  • php_pdo_firebird.dll

At command prompt, cast php -v and you will have an error:

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php\ext\php_interbase.dll' - The specified module could not be found.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pdo_firebird.dll' - The specified module could not be found.
 in Unknown on line 0
PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Install the Firebird…

Try again casting a command php -v

C:\Workspace\localhost\vshbdata>php -v
PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Meaning, the firebird is successfully installed.

Second test is create a php script:

<?php

foreach(PDO::getAvailableDrivers() as $driver) {
  echo $driver.'<br />';
}

?>

You should see firebird in the list…

jQuery Note ToolTip

Info.Tech, Web Development Comments Off on jQuery Note ToolTip

Screenshot:

note_tip

HTML:

<a href="#" class="note-tip" note="The quick brown fox jump over the lazy dog...">Hover here...</a>

CSS:

div.note-tip {
    padding: 10px;
    background-color: #fffbea;
    color: #646464;
    font-size: 10px;
    font-family: verdana;
    position: fixed;
    z-index: 999;
    top: 100px;
    left: 50%;
    -moz-border-radius: 8px;
    -webkit-border-radius: 8px;
    -khtml-border-radius: 8px;
    border-radius: 8px;
    border: 2px #e38008 solid;
    max-width: 250px;
    max-height: 120px;
    overflow: auto;
}

jQuery:

$(document).ready(function () {
    $('a.note-tip').mouseover(function(e) {
        $('div.note-tip').remove();
        var tip = $(this).attr('note');
        $('body').append('<div class="note-tip">' + tip + '</div>');
        $('div.note-tip').css('top', (e.pageY - (30 + $('div.note-tip').height())));
        $('div.note-tip').css('left', (e.pageX - (100 + $('div.note-tip').height())));
    }).mouseout(function() {
        if ($('div.note-tip').height() >= 110) {
            $('div.note-tip').mouseout(function() {
                $('div.note-tip').remove();
            });
        } else {
            $('div.note-tip').remove();
        }
    });
  });

Sorting Multi-Dimensional Array

PHP, Web Development Comments Off on Sorting Multi-Dimensional Array

I never tried sorting a an array using the inner array as a key for sorting. In this blog, been searching for the solutions and here it is…

Sample Data:

Array
(
    [0] => Array
        (
            [id] => 1
            [user] => c test1
            [data] => Array
                (
                    [a] => 1
                    [b] => 2
                )

        )

    [1] => Array
        (
            [id] => 2
            [user] => b test2
            [data] => Array
                (
                    [a] => 3
                    [b] => 4
                )

        )

    [2] => Array
        (
            [id] => 3
            [user] => a test3
            [data] => Array
                (
                    [a] => 5
                    [b] => 1
                )

        )

)

Sorting Code:

// sort multidimensional array... [start]

$test_data = array(
        array('id' => 1, 'user' => 'c test1', 'data' => array('a' => 1, 'b' => 2)),
        array('id' => 2, 'user' => 'b test2', 'data' => array('a' => 3, 'b' => 4)),
        array('id' => 3, 'user' => 'a test3', 'data' => array('a' => 5, 'b' => 1))
);

// temporary container for sorting...
$sort_data = array();

foreach ($test_data as $key => $row) {
	// sorting by id
	$sort_data[$key] = $row['id'];

	// sorting by user
	$sort_data[$key] = $row['user'];

	// sorting by a in the inner array..
	$sort_data[$key] = $row['data']['a'];

}
// sort as ascending...
array_multisort($sort_data, SORT_ASC, $contract_data);

// sort as descending...
array_multisort($sort_data, SORT_DESC, $contract_data);

// sort multidimensional array... [end]

That’s it.. It will be handy for those who love playing with arrays… 🙂

Edit Android Hosts file

Android, Info.Tech, Mobile Development, Web Development Comments Off on Edit Android Hosts file

I have a project that needs to be compatible with mobile devices. What I want  is to redirect my emulated android or AVD to my PC, like browsing http://grass.dev in the android browser, will lookup to my other PC in local network.

This guide is for Windows and in my case I am using Windows 7. So, go to your installed directory of the Android SDK, then go to X:\…\sdk\platform-tools\ then cast the commands below (you will be using adb commands).

adb remount
adb pull /system/etc/hosts /tmp/hosts

Above commands is to pull the hosts file from the android you currently running. Next thing you will do is edit the file. In my case,

127.0.0.1		    localhost
192.168.7.126		    grass.dev

That’s the content of my new hosts file. Next you need to push back the file to the android.

adb push /tmp/hosts /system/etc

 

That’s it.. it should work. 🙂

 

Remove Redundant Spaces, Tabs and New Lines

PHP, Web Development Comments Off on Remove Redundant Spaces, Tabs and New Lines

It’s been a while that I’ve been dealing with long text. Commonly, users input with redundant new lines, tabs, spaces and long words. Here’s my methods and just like others out there;

Removing redundant new lines or line breaks:

$str = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\n\n", $str);

Removing redundant tabs:

$str = preg_replace("/[ \t]+/", " ", $str);

Removing redundant spaces:

$str = preg_replace("/[ ]+/", " ", $str);

Shorten long word:

function ellipsis($str, $max = 45) 
{
	if (strlen($str) > $max) 
	{
		$str = '<abbr title="'.strip_tags($str).'">'.substr($str,0,$max).'...</abbr>';
	}
	return $str;
}

I think that’s all… Hope this will help you… 🙂

MySQL SPATIAL Index for GeoIP Database

Info.Tech, PHP, SQL: Structured Query Language, Web Development Comments Off on MySQL SPATIAL Index for GeoIP Database

Few days ago, I had an experimental project called Website Visitor Tracker which will track the visitor what city or country they from and plot their location to Google WebGL Globe and the source of the data have to query in 2M+ rows for the IP blocks and 290k+ rows for the cities or 91k+ rows for the countries. The problem occurs is the the query which it will take 2 to 4 seconds each IP query from the database and it is bad sign.

I found a solution suggested by BOTP from Kagaya-anon Linux Users Group (Thanks master BOTP) that I have to use SPATIAL Index. So I did and it works like a charm.

This is the output without using SPATIAL Index…

mysql> SELECT b.id,l.city,l.latitude,l.longtitude FROM geoip_ip_blocks AS b, geoip_locations AS l WHERE b.locID = l.locID AND INET_ATON('203.114.138.95') BETWEEN b.startIpNum AND b.endIpNum;
+---------+------------------+----------+------------+
| id      | city             | latitude | longtitude |
+---------+------------------+----------+------------+
| 1859525 | Palmerston North | -40.3500 |   175.6167 |
+---------+------------------+----------+------------+
1 row in set (1.71 sec)

mysql>

So here’s the steps implementing SPATIAL index…

First I created a new table…

create table geoip_blocks (
	id bigint(20) unsigned not null auto_increment primary key,
	locID bigint(20) not null default 0,
	startIpNum bigint(20) unsigned not null,
	endIpNum bigint(20) unsigned not null,
	ip_poly POLYGON not null,
	SPATIAL INDEX(ip_poly)
) engine=myisam;

Note: use MyISAM engine for this to apply SPATIAL index, otherwise you will encounter some issues. 😛

Next, export your current table of your GeoIP…

WINDOWS: 

select locID, startIpNum, endIpNum into outfile 
'c:/geoip_blocks.dat' fields terminated by "," enclosed by "\"" 
lines terminated by "\n" from geoip_ip_blocks;

LINUX:

select locID, startIpNum, endIpNum into outfile 
'/home/user/geoip_blocks.dat' fields terminated by "," 
enclosed by "\"" lines terminated by "\n" from geoip_ip_blocks;

Then import again but this time into the new table where you will insert into POLYGON type field.

WINDOWS:

LOAD DATA LOCAL INFILE "c:/geoip_blocks.dat"
         INTO TABLE geoip_blocks 
         FIELDS
            TERMINATED BY ","
             ENCLOSED BY "\""
         LINES
              TERMINATED BY "\n"
           (
               @locID, @startIpNum, @endIpNum 
             )
       SET
            id := NULL,
            locID := @locID,
           startIpNum := @startIpNum,
           endIpNum := @endIpNum,
           ip_poly := GEOMFROMWKB(POLYGON(LINESTRING(
          POINT(@startIpNum, -1),
          POINT(@endIpNum, -1),
          POINT(@endIpNum, 1),
          POINT(@startIpNum, 1),
         POINT(@startIpNum, -1))));

LINUX:

LOAD DATA LOCAL INFILE "/home/user/geoip_blocks.dat"
         INTO TABLE geoip_blocks 
         FIELDS
            TERMINATED BY ","
             ENCLOSED BY "\""
         LINES
              TERMINATED BY "\n"
           (
               @locID, @startIpNum, @endIpNum 
             )
       SET
            id := NULL,
            locID := @locID,
           startIpNum := @startIpNum,
           endIpNum := @endIpNum,
           ip_poly := GEOMFROMWKB(POLYGON(LINESTRING(
          POINT(@startIpNum, -1),
          POINT(@endIpNum, -1),
          POINT(@endIpNum, 1),
          POINT(@startIpNum, 1),
         POINT(@startIpNum, -1))));

And that’s it.. You are good to go for testing…

OUTPUT AFTER SPATIAL INDEX IMPLEMENTED:

mysql> SELECT geoip_blocks.locID, geoip_blocks.startIpNum, geoip_blocks.endIpNum
    ->  FROM geoip_blocks INNER JOIN geoip_locations ON geoip_blocks.locID = geoip_locations.locID
    ->          WHERE MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON('203.114.138.95'), 0)));
+--------+------------+------------+
| locID  | startIpNum | endIpNum   |
+--------+------------+------------+
| 199902 | 3413280768 | 3413283071 |
+--------+------------+------------+
1 row in set (0.19 sec)

mysql> SELECT geoip_blocks.locID, geoip_locations.city, geoip_blocks.startIpNum, geoip_blocks.endIpNum
    ->  FROM geoip_blocks INNER JOIN geoip_locations ON geoip_blocks.locID = geoip_locations.locID
    ->          WHERE MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON('203.114.138.95'), 0)));
+--------+------------------+------------+------------+
| locID  | city             | startIpNum | endIpNum   |
+--------+------------------+------------+------------+
| 199902 | Palmerston North | 3413280768 | 3413283071 |
+--------+------------------+------------+------------+
1 row in set (0.00 sec)

Hope this help for those who encounter the same problem I had… 🙂

Thanks again to Master BOTP & DATA BOB JR.

Reference: http://databobjr.blogspot.co.nz/2010/07/ip-to-country-lookup-table-using-mysql.html

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in