Tag Archives: PHP
Practical PHP Testing – Free Ebook

Practical PHP Testing – Free Ebook

Posted 04 January 2010 | By vinu | Categories: PHP | Comments

If you’re new to testing in PHP, and were wondering how to create and run automated tests, here’s an ebook which will help you get the basics right.

Practical PHP Testing is an ebook which is a compilation of  articles from Giorgio Sironi’s blog on Practical PHP testing.

This book takes you though the basics of PHPUnit – how to install it and start writing simple tests using PHP Unit. Here are some of what this ebook covers:

  • bonus chapter on TDD theory;
  • a case study on testing a php function;
  • working code samples, some of whom were originally kept on pastebin.com;
  • sets of TDD exercises at the end of each chapter;
  • glossary that substitutes external links to wiki and other posts, to not interrupt your reading with terms lookup.

More information and download link is available here.

Reblog this post [with Zemanta]
PHP 5.3 & Internationalization

PHP 5.3 & Internationalization

Posted 14 July 2009 | By vinu | Categories: PHP, Techniques, Web Development | Comments

Unicode_sampleStas Malyshev has written a good article over at Zend Developer Zone about the new intl – Internalization extension in PHP 5.3. Internationalization has been a major problem with web developers when developing sites which have to support multiple languages. The new extension eases the developer’s work drastically. Stas mentions in the article that the following modules have been implemented in the Intl extension:

  • Locale — deals with breaking locale data into components, assembling a locale string from components and displaying the names of countries, languages etc in a specified locale.
  • Collator — a means of comparing and sorting strings according to local rules.
  • Number formatter — allows you to format numbers in a variety of ways, and to parse textual representations of numbers.
  • Date formatter — allows you to format dates and to parse textual representations of dates.
  • Message formatter — allows you to compose messages from parameterized strings while formatting the data inside according to local rules and allowing choices dependent on the actual parameter value.
  • Normalizer — a means of bringing a Unicode string to a standard, unambiguous representation.
  • Grapheme module – handles parsing a string into a set of graphemes.
  • IDN – handles internationalized domain names format

Read Stas’ article to learn how to use the new features this extension provides to make your website Internationalization ready.

If you’re using PHP5.2, you’re in luck since there is a PECL package which should run on PHP 5.2.4 and newer over at: http://pecl.php.net/package/intl

Link: http://devzone.zend.com/article/4799-Internationalization-in-PHP-5.3

Image via Wikipedia

Reblog this post [with Zemanta]
PHP Compiler Internal Slides by Sebastian Bergmann

PHP Compiler Internal Slides by Sebastian Bergmann

Posted 28 May 2009 | By vinu | Categories: PHP | Comments

Here’s an interesting slide from Sebastian Bergmann which explains the magic that happens when you execute your PHP code, and how it gets converted into bytecode. He also goes ahead to show you how to extend the PHP compiler in the presentation.

Reblog this post [with Zemanta]
PHP Quick Profiler – Profile your Code

PHP Quick Profiler – Profile your Code

Posted 12 May 2009 | By vinu | Categories: PHP, Programming, Scripts, Software | Comments

PHP Quick Pofiler

Here’s a good looking and functional profiler you can plug into your projects. PQP (PHP Quick Profiler) allows you to profile your code and get information about how much time your script took to execute, the amount of memory used, the files which have been included, errors in your code, queries and any other debug information you would like to show up.

With minor changes to your code, it’s easy to get information on the console, memory and file utilizations. Getting information about your queries and load times, you’ll have to follow the instructions over at:  http://particletree.com/features/php-quick-profiler/.You can also send your exceptions, variable dumps and custom messages sent to the console.

See a demo of PHP Quick Profiler at - http://particletree.com/examples/pqp/

Get more information and download PHP Quick Profiler at: http://particletree.com/features/php-quick-profiler/

Reblog this post [with Zemanta]
PHP functions in Javascript using PHP.JS

PHP functions in Javascript using PHP.JS

Posted 08 January 2009 | By vinu | Categories: Javascript, PHP | Comments

PHP.JS Logo

PHP programmers usually have to handle HTML & Javascript front-end coding as well and I’m sure a lot of us have been frustrated with the lack of those easy to use PHP functions in Javascript like those array, encode/decode and string functions. Here’s a Javascript project which provides you just that.

PHP.JS is an open source project started by which aims at providing the standard PHP functions for Javascript development. This eases up programming in Javascript for PHP developers as they can use functions they are familiar with. Currently the project has ported around 230+ PHP functions.

To use this library all you need to do is to download the php.js file and include it in your page:

<script src="/pathto/php.js"></script>

Then use use the function as you would in PHP. For example if you want to use the urlencode function in Javascript, just use it like this in Javascript

urlencode('http://blogs.vinuthomas.com/');

This should return ‘http%3A%2F%2Fblogs.vinuthomas.com%2F’. As easy as that !

Edit: As Kevin mentioned in the comments below, don’t use the entire php.js file in your projects, just use the function you need.

History of PHP.JS from (phpjs.org):

A developer called Kevin van Zonneveld was once working on a project with a lot of client(JS) / server(PHP) interaction, and he found himself coding PHP functions (like base64_decode & urldecode) in JavaScript to smoothen communication between the two languages.

He stored the stored the functions in a file called php.js which was included in the project. But even when the project was done, it remained fun trying to port PHP functions to JavaScript and so the library grew.

Kevin decided to share the little library online, which triggered the enthusiasm of a lot of PHP developers longing for PHP functionality in JavaScript. The project was open sourced in 2008, and many people contributed their own functions in the comments sections of Kevin’s blog.

It was decided that the library deserved a bigger home, and a face of its own, and so the PHP.JS core team (which at that time also consisted of Michael White, Felix Geisendörfer, Philip Peterson) developed the phpjs.org website

Links:
PHP.JS Home Page
List of Functions available in PHP.JS
Download PHP.JS

Reblog this post [with Zemanta]
Roll out your own Social Network using Elgg

Roll out your own Social Network using Elgg

Posted 08 October 2008 | By vinu | Categories: PHP, Software | Comments

If you’re thinking of rolling out a Social Network project, try Elgg. You can launch your own Social Network without writing a line of code. :)

Elgg is a open source social network platform built on PHP. The best about Elgg is the ability to extend the base platform’s functionality by downloading or writing your own plugins. Some of the plugins currently available include – a blog engine, social bookmarks, message boards, OpenID signup and login, and more. For a complete list of plugins that Elgg supports, head over to: http://docs.elgg.org/wiki/Features

Elgg also won an award at Infoworld’s 2008 Best of Open Source  Awards.

Link: Elgg Official Site, Dowload Elgg, Documentation

Reblog this post [with Zemanta]

Zend Framework to get AMF support

Posted 13 August 2008 | By vinu | Categories: PHP | Comments

Andi Gutmans has announced that Adobe will be contributing towards AMF (Action Message Format) support on Zend Framework. This will allow with apps made in Flex or Adobe Air to communicate with PHP. Earlier, libraries like AMF-PHP allowed this interaction between Flash and PHP.

Adobe’s proposal for this support on the Zend Framework can be viewed over at: http://gourl.in/1p

Andi mentions over at his blog that AMF support is targetted for the Zend Framework 1.7 version.

More over at Andi’s Blog.

Reblog this post
Zend Framework Architecture @ PHP::Impact

Zend Framework Architecture @ PHP::Impact

Posted 29 July 2008 | By vinu | Categories: PHP | Comments

Federico Cargnelutti’s PHP::Impact blog has a good article which looks at the architecture of Zend Framework. He starts the article with a comparision of the Three-Tire and MVC Architecture and how MVC is used in Zend Framework. He also points out some of the cons of the framework.

“Zend Framework not only offers a solid infrastructure, but also an extensive component library. The component structure of ZF is somewhat unique, each component is designed with few dependencies on other components. This loosely-coupled architecture allows developers to use components individually.”

Read the article @: Zend Framework Architecture « PHP::Impact

Zemanta Pixie
mbstring Functions by default in PHP

mbstring Functions by default in PHP

Posted 18 July 2008 | By vinu | Categories: PHP | Comments
Complete set of printable ASCII characters. Th...Image via Wikipedia

When dealing with multiple languages and internalization in PHP, some of the default functions in PHP end up mangling up the unicode characters in PHP. This is evident when you have a lot of funny looking characters coming up on your web page instead of the actual characters. Apart from setting the UTF-8 headers in your HTML page, you should be careful on which functions you use to handle your strings. There is an extensions called mbstring which you can install in PHP which gives you a set of functions which are unicode ( actually multibyte ) ready.

ASCII characters store each character in one byte. Unicode characters like UTF-8 use multiple bytes to handle the wider range of character sets. Some of the built in functions in PHP assume each character is only one byte and ends up breaking multibyte characters due to this assumtion.

One way to ensure that your content doesn’t get mangled up is to substitue the regular php functions in your code with the mbstring variety. To get the entire list of mbstring functions, head over to: http://php.net/manual/en/ref.mbstring.php

A few examples of the function mapping are:

EMail Function : Instead of using mail, you could use the mbstring function mb_send_mail
String Functions: strtoupper becomes mb_strtoupper; strlen becomes mb_strlen, substr becomes mb_substr and so on…

Now instead of going in and changing all your code to become multibyte ready, PHP gives you an easy way to overload the default functions with the mbstring variety.

You can set a value to mbstring.func_overload in php.ini. The value set for this function decides which functionality is overloaded by default with the mbstring variety:

  • 1 – overloads the mail functions. So you don’t have to substitute mail with mb_send_mail in your code. The mail functuion it self will work like mb_send_mail if mbstring.func_overload is set to 1 in php.ini
  • 2 – enables string functions overloading
  • 4 – enables regular expression functions overloading
  • 7 – enables mail, strings and regular expressions overloading
Zemanta Pixie

Phalanger – PHP Compiler for .Net

Posted 16 June 2008 | By vinu | Categories: PHP | Comments

Phalanger is a new PHP implementation introducing the PHP language into the family of compiled .NET languages. It provides PHP applications an execution environment that is fast and extremely compatible with the vast array of existing PHP code. Phalanger gives web-application developers the ability to benefit from both the ease-of-use and effectiveness of the PHP language and the power and richness of the .NET platform taking profit from the best from both sides.

Phalanger maintains the way how PHP web applications are developed and deployed so that the you can leverage from .NET without having to learn complex ASP.NET style of web development, however Phalanger also allows you to use PHP as a language for writing ASP.NET applications, so you have the freedom to make a choice!

Due to the managed implementation of the PHP functions library, the migration from PHP interpreter to Phalanger is an easy and straightforward process, which includes only configuring the application in most of the situations. The compiled nature of Phalanger applications also leads to major performance boost.

To get an idea on how the interoperability of PHP and C# works, head over to one of the tutorials on their site: Using PHP library from C#

Links:
Download Phlanger
Phlanger Documentation
Tutorials

Zemanta Pixie