PHP :: remove special characters from a string

15 12 2009

This could be just a quick and easy help for someone who is wishing to remove special characters from some string OR wishing to just keep alpha numeric characters in the string. So here is the Regular expression for that:

preg_replace('/[^a-z0-9]/i', '_', $string)





Most useful PHP Libraries

26 11 2009

Did you faced such situation that you need to complete a project on early basis and you waste your big time to search for your required libraries and then knowing how to go for your integration? Yes .. such days often come in some software developer’s life ..

Open source matters! so PHP is at top for helping you by providing such a huge community where you get great “plug and play” stuff for attaining quicknees in your work.
In same respect, Today i am gonna share with you a list of 20 Most Useful PHP libraries about which every PHP developer must now. So here they are:

Charting Library

GD library may help you to create a good but simple chart but for complex charts, here are some great libraries:

  1. pChart – a PHP class to build charts.
  2. Libchart – Simple PHP chart drawing library.
  3. JpGraph – Object-oriented graph creating library for PHP.
  4. Open Flash Chart – Flash based charting library.

RSS Parser Library

Parsing a RSS gets painful sometime, so why don’t you prefer to use any of following libraries and enjoy???

  1. MagpieRSS – RSS for PHP.
  2. SimplePie – Super-fast, easy-to-use, RSS and Atom feed parsing in PHP.

Thumbnail Generator

Good way for generating Thumbnails.

  1. phpThumb – The PHP thumbnail creator.

Payment

Playing with an e-commerce site? Need payment solution?. Let this library help you ;)

  1. PHP Payment Library – PHP Payment Library for Paypal, Authorize.net and 2Checkout (2CO)

OpenID

Just in case you need to implement OpenID to your project.

  1. PHP-OpenID – OpenID implementation in PHP.

Database Abstraction/ORM

 These library let you smile more while writting SQL quries.

  1. ADOdb – Database abstraction library for PHP.
  2. Doctrine – Object relational mapper (ORM) for PHP 5.2.3+ that sits on top of a powerful database abstraction layer (DBAL).
  3. Propel – Object-Relational Mapping framework for PHP5
  4. Outlet – an Open source object-to-relational mapping tool for PHP.

PDF Generator

  1. FPDF – PHP class which allows to generate PDF files with pure PHP.

Excel

Enjoy if you need to generate your report in Excel file while using these libraries .

  1. php-excel – Very simple library for generating excel documents from php on-the-fly.
  2. PHP Excel Reader – Parse and retrieve information from XLS files.

E-Mail

Don’t like PHP mail function? Give a chance to any of these libraries:

  1. Swift Mailer – Free Feature-rich PHP Mailer.
  2. PHPMailer - Powerful email transport class with a big features and small footprint.

Unit Testing

For Test-driven development lover, these library will help great.

  1. SimpleTest – PHP unit test and web test framework.
  2. PHPUnit – Member of the xUnit family of testing frameworks and provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results.

Hope these libraries will make your programming life more easier and happy :)

Happy Coding ;)





its been long time …

20 11 2009

It’s been long time that i got chance to write some thing on my blog.

Sometimes, Life gets too busy and even you don’t find time for yourself but … We spend the time somehow ..

Hopefully you’ll see further informative and much logical stuff from my side (this wasn’t an announcement but a humble decision :) ).

See ya ;)





css tip : set margin parameters

31 10 2009

if you get confuse and feel hard to remember the parameter sequence for ‘margin’ tag in css then just bookmark the url of my this post :)

General Format:

margin:Toppx Rightpx Bottompx Leftpx

 

Example:

<div style=” margin:14px 10px 7px 16px;”>
This inline css code will make this div to produce margin: 14px at top, 10px at right, 7px at bottom and 16px at left

Hope this will help someone ;)





JQuery form validation :: a good solution

29 10 2009

hay Friends,

Do you want to validate your form using JQuery and want it to be Inline ?? so Here is the solution for that:
http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
I realy appericiate this article so thought to share with you all.

Hope you guys would love it like me ;)





Drupal 6 Cheat Sheets

27 05 2009

hay friends;

I was in search for some cheat sheets that could easily help me to remember the main constructs of Drupal 6 programming and eventually i found :) .
You may download the cheat sheet for Drupal 6 here:

Hope these would be helpful for someone other too.





Subversion :: some handy commands for SVN

20 05 2009

hello friends ;


If you guys are using SVN for version controlling and willing to get a list of handy commands that are usually used while operating with SVN (Subversion), then you must visit these pages:

  • http://wiki.greenstone.org/wiki/index.php/Useful_SVN_Commands
  • http://lipidity.com/apple/subversion-basics/
  • http://www.oxygenxml.com/doc/ug-oxygen/cmd-line-quick-reference.html

Those fortunate who have abundant time for learning should visit this link http://svnbook.red-bean.com.
SVN may really ease your life if you are really interested ;)





Magento: retrieve base url path

20 05 2009

If you are working in Magento and trying to find the base URL path for your Magento installation then you must use try this line of code:
echo Mage::getBaseUrl();

It will fairly return you the base path Url. Hope this tip will help someone :) .





Drupal Book :: drupal 6 javascript and jquery

4 05 2009

hay Friends,
Another good book for Drupal community: Drupal 6 JavaScript and jQuery released by Packt. This is 2nd great book by ‘Matt Butcher’ released on March 2009. This book greatly explain how to make it easy to work in Drupal using jQuery or simple java script. I read a free chapter of this book and i found it well versed about using JQuery in Drupalish modules. I am really dying to read this cool book :P .

A good Book for Drupal 6 and JQuery

A good Book for Drupal 6 and JQuery

Hopefully, I’ll get it very soon INSHAALLAH :) .





Drupal 6 :: Custom Search Box

29 04 2009

hello Friends,

I came across a scenario where it was needed to customize Drupal 6 search box for my current drupal based theme and this customization was needed to :

  1. Change Default text on submit button
  2. Change Default text in search box (Search this site)
  3. When user clicks on search box, default search box text should disappear

All of above tasks should be easily attainable if you are not working in Drupal but it doesn’t mean that these are very difficult while working in Drupal. Somehow, it is a little tricky.

Most recommendable and suitable way that i found was to create a new module and use form_alter hook to track the search form events and bring all above changes in these events.

I’ll recommend you to read this thread: http://drupal.org/node/214592 where Heine helped alot to get clear ideas about form_alter hooks and their usage. Hopefully it will help you too.

Now lets move towards the solution.

First of all create a new module under sites/all/modules with any name. Say it is named ‘abc’ (supposing that you will be aware of the process of module creation and all files needed to create for a new module in Drupal). Open your abc.module file and create a new function there named ‘abc_form_alter‘ having parameters (&$form, $form_state, $form_id).  Basically, ‘abc_form_alter‘ will implement hook_form_alter (explained well http://drupal.org/node/214592) and will use this function to grab search form events and implement my search box changes on triggering of those events.  So this is the summary of our solution and following code you’ll write in abc.module file.

function abc_form_alter(&$form, $form_state, $form_id) {
  if($form_id=='search_theme_form')
  {
	$form['submit'] = array('#type' => 'submit', '#value' => t('[ GO ]'));
	$form['search_theme_form']['#default_value'] = 'Search My Site';
	$form['search_theme_form']['#attributes'] = array('onfocus' => "if (this.value == 'Search My Site') {this.value = '';}" );
  }
}

and That’s All :) .

Lets make a short review on above code,

This condition if($form_id==’search_theme_form’) will check if ’search_theme_form’ is about to render then do following stuff:

 $form['submit'] = array('#type' => 'submit', '#value' => t('[ GO ]'));

Above Line will change the default submit button text and make it to be [ GO ]

 $form['search_theme_form']['#default_value'] = 'Search My Site';

This code Line will Change Default text in search box and make it to be ‘Search My Site’

 $form['search_theme_form']['#attributes'] = array('onfocus' => "if (this.value == 'Search My Site') {this.value = '';}" );

This final code line gives the way to change any attribute for this text box (you may use it to change the default css class used for search box, too). Here i changed the ‘onfocus’ attribute and wrote the javascript code so when user click on search box for searching some keyword, search box’s default text (Search My Site) should get vanished.

One last thing, if you’r at very basic level in Drupal or even not a programmer then i’ll recommend you to go for this module Custom Search Box. This module is good but keep in mind that you won’t have everything in your hand while using this module but above process can help you to play freely with search form attributes.

I hope this post will open new horizons for you to customize any Drupal based Form :) .