Skip to main content

Posts

Showing posts with the label php

Super mkdir helper function for php

Here's a handy little function to force-create directories in PHP. If the directory does not exist, it will create it. If there is a file with such a name, it will delete that file and create the directory in its place. Params: same as  http://us.php.net/manual/en/function.mkdir.php Returns: true on success (the given path is now a directory), false on error function super_mkdir($file, $mode = 0777, $recursive = false) { if (!file_exists($file)) return mkdir($file, $mode, $recursive); if (is_dir($file)) return true; if (!unlink($file)) return false; if (!mkdir($file, $mode, $recursive)) return false; return true; } I will possibly have a better version later which would return error codes instead of just false...

Ruby on Rails vs PHP

In my past experience with Web Apps, I have worked with PHP (with MySQL). Now I'm working on my website and using PHP again. At work, however, we are using Ruby on Rails (RoR), with Oracle. This makes me want to do a comparison of the two. Obviously, I will compare RoR and PHP, but both using a MySQL database. Keep in mind that this is based on my impressions, not necessarily the best technical aspects of each language. RoR Advantages: RubyGems - It's extremely simple to install extra features (calendar date select, etc). Yeah, you can have libraries in PHP, but it's not as simple and polished as RoR. You can even define gem dependencies your app has in environment.rb and then use "rake gems:install" to install all gems your project requires. Layouts and Partials - Let's face it: having a "standard.html.erb" layout (or template, if you will) and then having "" in it is just beautiful . Whatever content you create will automatically (or au...