Archive for PHP

PHP tip: Best way to get file extension

// July 25th, 2010 // 2 Comments » // PHP, PHP Tips

I tried 100 ways to get the file extension from a complete file path including directories and file name with extension. This one works perfectly. This uses php function pathinfo to get the directory name, filename and its extension for you which is very handy.

<?php
$fileinfo = pathinfo(“/path/to/your/file.php”);
echo $fileinfo['dirname']; // Get directory
echo $fileinfo['basename']; // Get file basename
echo $fileinfo['extension']; // Get file extension
echo $fileinfo['filename']; // Get file name
?>

Testing zend optimizer encoded PHP applications

// July 4th, 2010 // No Comments » // PHP, PHP Tips

I am working on an expressionengine application these days. As I am using the beta version of expression engine until they release the final version, so the source files are encoded with the zend optimizer. Zend optimizer has a limitation that it can’t work with version 5.3 of PHP so far.

I had the latest XAMPP installed on my Windows VISTA machine for a year now but I found out that Zend optimiser isn’t compatible with version of PHP it provided i.e PHP 5.3, so I downloaded the version 1.6.8 of XAMPP from http://sourceforge.net/projects/xampp/files/ which has the older version of PHP i.e 5.2 which is compatible with Zend Optimizer.

Now here is the thing, I downloaded the Zend Optimizer from this link and installed it.  In its installation steps it asks you for two locations which you have to tell it correctly or else it will not work properly.

  1. The path to php.ini
  2. The path to Apache websrver’s root.

Based on the installation directory of your XAMPP, you can select appropriate directories in these steps. I chose default C:\xampp while installing XAMPP,  so I selected C:\xampp\apache\bin and C:\xampp\apache for the Steps 1 and 2 respectively.

And before that, using XAMPP control panel, I had stopped the Apache so when the configuration changes take place, the next time apache runs, it loads this new php.ini file which is changed by the zend optimizer installation.

Next thing you want to do is, check the php info using phpinfo.php file using the follwing url.

http://localhost/xampp/phpinfo.php

It will open up a page with a bunch of information. Look for the text  Loaded Configuration File and open the same php file using windows explorer.

For me it was

Loaded Configuration File C:\xampp\apache\bin\php.ini

So I opened the php.ini folder and searched for the line where Zend Optimiser properties were mentioned and

[Zend]
zend_extension_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\ZendExtensionManager.dll"
zend_extension_manager.optimizer_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\Optimizer-3.3.0"
zend_optimizer.enable_loader = 0
zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

[Zend]zend_extension_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\ZendExtensionManager.dll"zend_extension_manager.optimizer_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\Optimizer-3.3.0"zend_optimizer.enable_loader = 1zend_optimizer.optimization_level=15;zend_optimizer.license_path =; Local Variables:; tab-width: 4; End:

In the above code I changed


zend_optimizer.enable_loader = 0

to


zend_optimizer.enable_loader = 1

So its loaded the next time I start the apache.

PHP: Text cropping with defining the number of characters, words or sentences

// March 18th, 2009 // 2 Comments » // PHP, PHP Tips, Web Development

I have recently been working on PHP RSS reader script that was supposed to do three different things with RSS description text. To make a teaser RSS text, I was asked to develop the functionality in a such a way that text can be cropped in these three ways.

  • with defining the number of words.
  • with defining the numbers of characters.
  • with defining the number of sentences.

Here is a set of functions that helps you crop a text in three different ways. The usage of the function is also mentioned at the end f the script. (more…)

How to make sure your PHP RSS feed reader doesn’t mess up

// March 18th, 2009 // No Comments » // PHP, PHP Tips, Web Development

I was recently working on a custom RSS feed reader where the prior most concern of the client was being able to crop the text with respect to the

  1. Number of words.
  2. Numbers of characters.
  3. Number of sentences. (more…)

I am on home page of oDesk, feels great

// March 17th, 2009 // 1 Comment » // PHP, Portfolio, Web Development, Wordpress

Hi guys

I am feeling good right now. Have been working on oDesk from Feb 17, 2009. And its good you get paid on hourly basis. I like oDesk the most among freelancing sites I have worked on. Anyhow, I took a few screen shots to show you that I was once featured on home page on oDesk.

(more…)

Yahoo Shortcuts

// September 9th, 2008 // No Comments » // Blogging Engines, Open Source, PHP, Plugins, Wordpress

 Enhance your blog posts with Yahoo! Shortcuts.

Enhance your blog posts with Yahoo! Shortcuts.

As you type the content for your blog post, this plugin looks for Flickr Photos, Maps to any locations that you might mention in the post, any products that are listed or even related news to your blogs post.

If your content regularly mentions some companies regularly, Yahoo shortcuts can bring up latest financial information related to that company.

Relevant search results would also come up for certain terms like in the image shown UNIX Pipes would pop up a Yahoo shortcut with relevant contextual search results. Some bloggers may find some shortcuts annoying and irrelevant to their blogs content, but some might really find it useful. It all depends on what you blog about. (more…)

Converting comma separated integer/ digit values to an array of integers

// September 9th, 2008 // No Comments » // PHP

OK here is the code to convert a comma separated string of integer/ digit value to an array

$csvintegers='1,2,3,4,7';
$listvals=split(",",$csvintegers);
?>

You can always compare whether if an integer is present in a string or not. The code to do so is (more…)

Convert date formats between PHP and MySQL (mm/dd/yyyy to yyyy-mm-dd)

// September 8th, 2008 // 1 Comment » // CodeIgniter, PHP, Web Development

I have a view in HWC where I am using Javascript DHTML date picker script to pick the date and insert into test field. By the way HWC is the PHP-MVC (using codeigniter) application I am working on.

Date Picker in dhtml/Javascript

Date Picker in dhtml/Javascript

(more…)

Codeigniter – Clean URLs – Apache mod rewrite : Removing /index.php/ from URL in CodeIgniter Application

// August 22nd, 2008 // 8 Comments » // Articles, CodeIgniter, Frameworks, PHP, Web Development

OK readers, here is a simple method to achieve clean urls with your PHP application developed in CodeIgniter.

Please note that this method is applicable only to applications developed in CodeIgniter. Much of the content has been taken from CodeIgniter wiki but rewritten in my own way. (more…)

WordPress; the new cool version 2.5 enjoyyy

// March 30th, 2008 // No Comments » // Blogging Engines, Open Source, PHP, Wordpress

Yeah as always I am one complete day late to know about the new release of wordpress. Its really cool. I just downloaded and installed it. As its famous for its 5 minutes install; it has great new features and a neat and clean interface, I think a hundred times better than the previous version thats 2.3 if I am not wrong (2.3.3), yeah I just checked as I am writing this post on the old platform and I just needed to scroll down this post window (my wordpress blog is an auto install by Fantastico provided by my host in Cpanel)

Anyhow right now I am playing with the latest version (2.5) and its simply awesome.

See the difference. Its just obvious. Its on full page for this blog post. (more…)