Enabling apache and PHP in OSX (Snow Leopard)

June 28, 2010 · Posted in Mac, PHP · Comment 

OS X Snow Leopard (10.6.x) comes with local apache server with lots of extensions/modules. You just need to configure (very easy) them in order to use it.

If apache is already configured (it should be), you can run it by:

sudo apachectl start

To check, if it is running, do this:

ps -aux|grep httpd

Then the typical output would be:

bgates 50737 0.0 0.0 2426844 328 s003 R+ 9:52AM 0:00.00 grep httpd
_www 50702 0.0 0.0 2451752 656 ?? S 9:43AM 0:00.00 /usr/sbin/httpd -D FOREGROUND
root 50701 0.0 0.2 2451752 9768 ?? Ss 9:43AM 0:00.51 /usr/sbin/httpd -D FOREGROUND

To enable php, you have to modify some configuration files:

find /etc/apache2/http.conf and uncomment it (remove the “#”)

#LoadModule php5_module libexec/apache2/libphp5.so

Then start/restart the apache instance by:


sudo apachectl start

or

sudo apachectl restart

PHP: str_word_counter does not count numerals

February 19, 2010 · Posted in PHP · Comment 

Realized that str_word_counter() does not count numerals (just numbers alone without alphabets) as a word.

The manual’s expression is:

mixed str_word_count ( string $string [, int $format = 0 [, string $charlist ]] )

If we supply “ab cd ef”, then the function returns 3, and if we supply “11 22 ab”, then it would be 1 since the function just ignores the numerals only value. The workaround (although it is not a bug or anything. It is a feature.) is to use the “$charlist”.

str_word_count ( string $string [, int $format = 0 , “0123456789” )

Then the numerals will be treated as letters.

T_PAAMAYIM_NEKUDOTAYIM?

February 7, 2010 · Posted in PHP · Comment 

What the heck is “T_PAAMAYIM_NEKUDOTAYIM” ???

When you are programming classes in PHP, you might encounter this error.

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in xxxxxx on line nn

Well, basically you screwed up some static scope reference somewhere. The origin of this error is something to do with the origin of PHP. According to wiki, the language was once worked on by two Israeli developers:

paam –> One

ayim –> Doubled

nekudot –> Dot

ayim –> Doubled

Seems like it means “double-colon” in Hebrew.  (static class reference)

The easiest way to reproduce is:

<?php

$test::bogus();

?>

For many ways, the above reference method is wrong…