PHP

Setup Xdebug with Zend Server CE

January 20th, 2012 0 Comments

Open Zend Server page, http://localhost:10081/

Disable “Zend Debugger”

Download xdebug.so binary which I suggest to download at -> http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging

Extract the archive and browse into ’5.3′ folder then copy ‘xdebug.so’ to ‘/usr/local/zend/lib/php_extensions’

Open ‘/usr/local/zend/etc/php.ini’ and add the following lines above [zend] section:

zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_host=”localhost”
xdebug.remote_port=9000
xdebug.show_local_vars=On
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20

Now restart your Zend Server by ‘sudo /usr/local/zend/bin/zendctl.sh stop’ and ‘sudo /usr/local/zend/bin/zendctl.sh start’

5 Things When Considering A Web Development Framework

May 10th, 2011 0 Comments

There are so many frameworks in web development that, to be frank, most developers find it confusing at times. Many developers are jumping around from one to another, if for no other reason, to add it to their resume. This article is designed to help cut through the confusion, and the bias online, and provide some thoughts that will help in your decisions.

This is a basic list of things to consider when choosing a framework:

1. Who’s behind the framework? Is it backed and endorsed by a large company, or perhaps a small group of developers looking to make a name, or otherwise just a new company looking to emerge? This should be very important in making a decision with not only the current framework you use with your projects, but even deeper, the platform and technology direction overall.

2. Is the code constantly being updated, tested, and maintained by a large professional team of developers? Technology changes, and so should the frameworks you use. It’s a constant pursuit to improve and debug that requires a lot of resources and man hours.

3. The code base should be of the highest quality, fully standardized and professional coding practices that will stand the test of time. It’s not about being a perfectionist, but it is about creating real solutions with solid products that have a reasonable life cycle.

4. A framework is only as good as it’s documentation and support. If it’s not easy to use, if it’s doesn’t produce better products, if it’s not speeding the time of development, then there is no point at all in even attempting to use it. This happens from great efforts to clearly document and to demonstrate common scenarios with written and video tutorials, etc.

5. What kind of work do you want? Do you want to work with professional organizations and long term contract work or jump from client to client with short turn around low level work? You must choose the technology path that meets your goals, and just the same, the framework goes nearly hand in hand with that direction.

Now that we know how you should choose, let’s look at the current options:

Tier 1:
Microsoft – .NET
JAVA – JSF

Tier 1 options are driven by large commercial for-profit companies with a large number of developers supporting and maintaining them, a large amount of money backing them, and are solid “enterprise worthy” directions. As a result, they are found as your tier 1 options.

Tier 2:
JAVA – Struts
JAVA – Spring
PHP – Zend Framework
Python – Django

Tier 2 options are also driven by quality companies with a large number of developers supporting them, and are solid directions that are considered “enterprise worthy” in many cases. Django may be a surprise by some, however, Python has proven to be a force to reckon with in the development community, and Django has played a large part in that movement. The other options in this tier should be no surprise.

Tier 3:
Ruby – Rails
PHP – Yii
PHP – Symfony
PHP – CodeIgniter

Tier 3 options are solid options, however, they are for the most part community driven by a smaller group of developers. Tier 3 options tend to be popular for a few years, then lose traction. They are also prone to complete overhauls where the framework is built again from the ground up to address issues and poor long term vision, which may break functionality of existing projects.

Tier 4:
If you’re not in the first 3 tiers, one should question whether you’re willing to roll the dice on such a development path for your projects. Sure, anyone can build their own framework, and many of the tier 4 and lower options are just not stable enough to guarantee their future.

Some may agree with the assessments, and of course, some will not as their favorite framework falls lower on the scale then expected. However, the vast majority of non-biased software/web/mobile architects will agree with these findings. With that said, there is no “wrong” framework to use provided it eases your development process, but if you’re looking for career paths and long term life cycles, you should consider these 5 points.

12 Regular Expressions To Improve Your PHP Development

September 6th, 2010 0 Comments

In programming, regular expressions are a very useful tool designed to validate, search, and match text patterns. In this article, I have compiled more than 10 incredibly useful regular expressions, for any language, that will probably be very beneficial to you.

Validate an URL
Is a particular url valid? The following regexp will let you know.

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/
Source: http://snipplr.com/view/19502/validate-a-url/

Validate US phone number
This regexp will verify that a US phone number is valid.

/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/
Source: http://snippets.dzone.com/posts/show/597

Test if a password is strong
Weak passwords are one of the quickest ways to get hacked. The following regexp will make sure that:

Passwords will contain at least (1) upper case letter
Passwords will contain at least (1) lower case letter
Passwords will contain at least (1) number or special character
Passwords will contain at least (8) characters in length
Password maximum length should not be arbitrarily limited

Get code within
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
Source: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=297

Get code within
If for some reason you need to grab all the code contained within the tags, this regexp will do the job:

<\?[php]*([^\?>]*)\?>
Source: http://snipplr.com/view/12845/get-all-the-php-code-between/

Match tel: urls
In a recent post, I showed you how you can use iPhone special link prfixes to automatically call someone.
This regular expression will match those tel: urls.

^tel:((?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=(?:\+[\d().-]*\d[\d().-]*|(?:[a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*(?:[a-z]|[a-z][a-z0-9-]*[a-z0-9])))(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*(?:,(?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=\+[\d().-]*\d[\d().-]*)(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*)*)$
Source: http://tools.ietf.org/html/rfc3966#section-3

Validate US zip code
When building a registration form, it is common to ask the user’s zip code. As forms are often boring, there’s a strong chance that the user will try to register false data. This regular expression will make sure he entered a valid American zip code.

^[0-9]{5}(-[0-9]{4})?$
Source: http://reusablecode.blogspot.com/2008/08/isvalidzipcode.html

Validate Canadian postal code
This regexp is very similar to the previous one, but it will match Canadian postal codes instead.

^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$
Source: http://reusablecode.blogspot.com/2008/08/isvalidpostalcode.html

Grab unclosed img tags
As you probably know, the xhtml standard requires all tags to be properly closed. This regular expression will search for unclosed img tags. It could be easily modified to grab any other unclosed html tags.

]+)(\s*[^\/])>
Source: http://snipplr.com/view/6632/grab-any-unclosed-xhtml-img-tags/

Find all CSS attributes
This regexp will find CSS attributes, such as background:red; or padding-left:25px;.

\s(?[a-zA-Z-]+)\s[:]{1}\s*(?[a-zA-Z0-9\s.#]+)[;]{1}
Source: http://snipplr.com/view/17903/find-css-attributes/

Validate an IBAN
I have recently worked on a banking application and this one was definitely a life-saver. It will verify that the given IBAN is valid.

[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}
Source: http://snipplr.com/view/15322/iban-regex-all-ibans/

Validate a BIC code
Another one very useful for any banking application or website: This regexp will validate a BIC code.

([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)
Source: http://snipplr.com/view/15320/bic-bank-identifier-code-regex/

If you’re interested in regular expressions, make sure you have read our “15 PHP regular expression for developers” post.