Sep
15

Who says Ruby on Rails is better than PHP?

Ruby, PHP

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

To the new programmers who think Ruby is the new fangled programming language, think again!

Sure, Ruby is newer, fancier, and even promises faster development time compared to tired old programming languages like PHP. That’s what Derek Sivers of popular CDBaby.com website thought. He took two years to convert his ‘messy’ PHP codes to Ruby on Rails. After 2 years he found out that things were not as easy as he thought. Swallowing his pride he went back to PHP and finished the required features he needed in 2 months !! Of course he tries to save his ego by mentioning that what he learnt in Rails, he applied in the new PHP codes :)

Read his article on 7 Reasons I switched back to PHP after 2 years on Rails

Jul
15

Useful PHP libraries

PHP

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

I’m playing with the idea of writing my own custom CMS for a future project.
Actually I’ve also chosen similiar libraries for one of my major CMS project 5 years ago!! Since the tools are still used today, they have stood the test of time.

To build a nice supporting libraries, I’ve chosen the following:

Smarty templating engine(last update:March 7th, 2007)
One of the best templating system in PHP in my opinion. Basically it’s a good idea to separate PHP code from html. For newbies, you may need to invest a little time to get used to the idea but it’s worth it.
Also, the caching system is pretty nice as it caches common PHP generated files into static HTML making retrieval and display on browsers many times faster and less taxing on the webserver. All good things to have!

ADODB (last update:May 20, 2007)
Data Abstraction library. Basically it replaces all the common database query commands with it’s own. This means if an app has already been written to support MySQL, changing it to another DB sysytem such as MSSQL only requires a one or two line change in the configuration file.

Scriptaculous(last update: May 25th, 2007)
Ajax library. To have those nice AJAX dynamic pages. Update portion of pages without entire page refreshes. Just so essential if you want your app to have the Web 2.0 feel :)

I really want to use CakePHP too as a framework to really cut development time down but I found it hard to learn. I’m still persevering and trying to pick it up by next month but in the meantime, I’ll continue with the above libraries.

Powered by ScribeFire.

Jul
13

Date validate

PHP

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

My friend Shaun asked me if PHP can do a date validation and I was sure it could with all the built-in date function. So no reason to write a custom date validation function from scratch.

A quick google search and check on php.net shows that you can use PHP’s checkdate function to do the validation.

Here’s an example:-


Here’s the full source code:


<form method=post action=<? $_SERVER[’PHP_SELF’] ?>>
    Enter date<input type=text value=” name=dt>
    <input type=submit>
</form>
<?

  if (isset($_POST[’dt’])) {
      if ($_POST[’dt’]==”) {
           echo  “Please enter a date”;
           die();
      }
      validate();
  }

  function validate() {
        $dt=$_POST[’dt’];
        //$dt=”02/28/2007″;
        $arr=split(”/”,$dt); // splitting the array
        $mm=$arr[1]; // first element of the array is month
        $dd=$arr[0]; // second element is date
        $yy=$arr[2]; // third element is year
        If(!checkdate($mm,$dd,$yy)){
        echo “invalid date”;
        } else {
        echo “Entry date is correct”;
      }
  }
?>