Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 
Blog Feed

Archive for February, 2008

Debugging PHP code using debug_backtrace

Thursday, February 28th, 2008

Most of the PHP developers debug php code in their local machine just by trial and error using “print_r”,”var_dump” and “echo”. They dont write unit tests or follow any advanced debugger like xdebug. But the problem of using these methods is you cannot fool proof your code and their might be some bugs still present in your code. Lets see how can we debug our code more effectively getting more information from the php interpreter itself. There is a nice function called debug_backtrace() is available in PHP to trace the root of an error. As the name implies, you can trace the execution of you code which produces the error. Have a look at the following code.


<?php
function processUserInput($a, $b)
{
echo divide($a,$b);
}
function divide($c, $d)
{
print_r(debug_backtrace());
}
echo processUserInput(4,0);
?>

This will output the following one

Array
(
    [0] => Array
        (
            [file] => PHPDocument1
            [line] => 5
            [function] => divide
            [args] => Array
                (
                    [0] => 4
                    [1] => 0
                )

        )

    [1] => Array
        (
            [file] => PHPDocument1
            [line] => 14
            [function] => processUserInput
            [args] => Array
                (
                    [0] => 4
                    [1] => 0
                )

        )

    [2] => Array
        (
            [file] => /home/hasin/Zend/ZendStudio-5.5.0/bin/php5/dummy.php
            [line] => 1
            [args] => Array
                (
                    [0] => PHPDocument1
                )

            [function] => include
        )

)

Getting Dell BCM4328 Wifi Card Working on Ubuntu 7.10

Wednesday, February 27th, 2008

After trying,searching and crying for more than one month, I finally get it working today in my laptop (Dell Inspiron 6400) :) - I am one of the happiest ever in this world right now :D. here’s how to. All the credit goes to “kayvortex

Model of my wifi card is “Broadcom BCM4328 802.11a/b/g/n (rev 01)”

Steps

1. Install Ndiswrapper Common and Ndiswrapper Utils (You can do it using synaptic)
2. Download The Driver from ftp://ftp.dell.com/network/R151517.EXE and unzip it somewhere. You will see a folder named DRIVER
3. Execute the following commands


sudo ndiswrapper -i /download_directory/DRIVER/bcmwl5.inf
sudo ndiswrapper -l
sudo modprobe ndiswrapper

4. Then, set ndiswrapper to load on startup:

sudo ndiswrapper -m
gksudo gedit /etc/modules

and add the following module to the list


ndiswrapper

5. Restart (This is a must)

Now you can use Fn+F2 to turn on your wifi :D )

How to Measure SEO Success

Wednesday, February 27th, 2008

If you’ve just completed the first steps of your SEO campaign, you’re probably sitting there thinking “There’s no way my SEO campaign can fail!”

Really? Then again, how does one measure success with SEO? Do you have to be #1 in search results for ALL the keywords you want? But that sounds impossible! How then do you measure if your campaign is successful?

(more…)

Zend Framework: The Best Framework for Use With Other Frameworks

Wednesday, February 27th, 2008

Here’s an interesting sales pitch. Using a PHP Framework? Cool. Just make sure you add Zend.

The Zend Framework is a fairly standard, (optionally) MVC PHP application framework. It comes with all the usual functionality; request routing, database access, templates (through view files) etc. It also comes with a lot of extra functionality that you might find useful in your application, including some of the best web services libraries available, especially when working with Google’s APIs.

(more…)

Subversion Hook

Tuesday, February 26th, 2008

Subversion hooks allow you to do some interesting stuffs at specific svn events which you can not do otherwise. For example consider the followings

1. Inform all users of that repository right after any commit
2. If some one locks a file, inform the admin after a successful unlock
3. Keeping track of commits made by any user
4. Do anything after the following event occurs

Start Commit
Pre Commit
Post Commit
Pre Lock
Post Lock
Pre Unlock
Post Unlock
Pre Revision Property Change
Post Revision Property Change

So how to do it? open the hooks folder under your repository folder and find there are files identical to these events. So if you want to do something, for example, after any commit then open post-commit.tmpl file and write code inside it. Write code in python, php, perl, bash or whatever and make that file executable using “chmod” and you are done. Subversion server will take care of the rest.

Checking leap year - the JS way

Monday, February 25th, 2008

The algorithm for checking leap year is like the one below

1. if the year modulo 400 is 0 , its a leap year
2. else if the year modulo 100 is 0, then its not a leap year
3. else if the year modulo 4 is 0, its a leap year
4. else its not leap year

In plain JS, it will look something like the following one


function checkleapyear(year)
{
year = parseInt(year);

if(year%4 == 0)
{
if(year%100 != 0)
{
return true;
}
else
{
if(year%400 == 0)
return true;
else
return false;
}
}
return false;
}

I have seen this in numbers of web sites who are dealing with dates. But why bother when you can do it in the “Javascript way” - yes, take advantage of this fantastic language - heh heh. The following piece of code will do it for you


var dt = new Date(year+"/02/29");
if ("1"==dt.getMonth()) alert("leap year");
else alert("not leap year");

The Art of Linkbaiting

Monday, February 25th, 2008

People who are involved in SEO know the importance of links. They want and need links, lots of links. Some buy them, some plead for them while some submit them to directories for those coveted one-way links.

While others, they bait them. Linkbait them, that is.

Don’t be put off by the name. Though it sounds nasty, Linkbaiting is a kind of a misnomer. In a sense, you “bait” people with something that they would want to link to. The result: you get to reel-in more traffic and an increase in popularity. But of course, just like in real fishing, you can’t catch fish with rubber as bait. The bait must be something that the people would want. So what can you use as linkbait?

(more…)

Head to php|tek!

Monday, February 25th, 2008

In my post on professional development for PHPers, I discussed the value of attending conferences. Well, php|tek in Chicago is coming up, and you should be there! The php|architect team has reported more than 40% of seats have been reserved already, so get in quickly.

If Chicago isn’t an option for you, try PHP Quebec, php london or the DC PHP Conference.

Paul Reinheimer’s PHP Contest

Saturday, February 23rd, 2008

Paul Reinheimer, a senior trainer for php|architect, is running another PHP contest. And you should enter.

Given an arbitrary (but valid) HTML file, retrieve all the links that would be displayed as hyper links and display them sequentially, having removed any duplicates. You may use any built in function, the phpinfo() of the server used for testing will be attached. You just need to retrieve the links, you don’t need to worry about them being relative or absolute.

Very straightforward, no? The trick is doing it well, and Paul intends to thoroughly test your entry.

So, why should you enter? First, it gives you a chance to test your PHP skills in a new environment - experimentation. You not only have to build the script, you have to build it well, and quality isn’t always a criteria in your day-to-day development. You might also learn something new, especially if you don’t often work with the string functions or regular expressions.

Head over to his post on the c7y boards and give it a go.

By the way, you might find this tutorial on link scraping useful.

Delphi for PHP - the lost RAD IDE

Saturday, February 23rd, 2008

Google Trends graph for “Delphi for PHP”:

Is it time to start preparing our Delphi for PHP eulogy? (more…)


Blog Categories Blog Archives
Advertise with Us!



Tutorials Scripts Web Hosting Developer Manuals
Resources