Category Archives: PHP

Oracle with PHP5 on Linux

Very nice and useful tutorial on how to run Oracle with PHP5 support on Linux (Debian) can be found on http://remorse.nl/weblog/debian_oracle_xe_and_php5/
Note Also be sure to set the NLS_LANG environment variable to the www-data user.

phpMyAdmin change session expire time

To change phpMyAdmin’s default session expire time (1800 s), change the ‘LoginCookieValidity’ setting to whatever value of seconds You like.
From the phpMyAdmin’s wiki’s Config page.
LoginCookieValidity
Define how long (in seconds) a login cookie is valid.
$cfg['LoginCookieValidity'] = 1800;
Maximum value is 2^31-1 , which is around 2.1 * 10^9. This is about 58 years.
If you are on a [...]

Point in triangle

A function in PHP to check if a point is in triangle.
 
 
function fAB($t, $x, $y) {
return ($y – $t[’y1′])*($t[’x2′] – $t[’x1′])
-($x – $t[’x1′])*($t[’y2′] – $t[’y1′]);
}
 
function fBC($t, $x, $y) {
return ($y-$t[’y2′])*($t[’x3′]-$t[’x2′])
[...]

Pythagorean triple in PHP

Pythagorean triple is every integer a, b and c for which a2 + b2 = c2 or in other words the a, b, and c are the sides of a right triangle. To generate triples in PHP, you can use the following function:
 
function CalcTriple($n){
$res = array();
[...]

Banner widget for Wordpress

I spent almost two hours, looking for Wordpress widget, which supports multiple instances and can embed banners into the sidebar. It looks like the solution is dead simple. Just use an instance of the default Text Widget and paste the HTML code for the banner inside.

Get band’s top songs from last.fm

Last.fm is great service. It provides a lot of information, which I find particularly useful for scenata.com. This is an example on how to get band’s top listened songs with the Audioscrobbler’s Webservices API using PHP’s XML Parser. The XML feed is formed as follows:
http://ws.audioscrobbler.com/1.0/artist/artistname/toptracks.xml
The function to use is
function GetFromLastFm($bandname)
and it returns an [...]

Prime numbers in PHP

This is quite fast (but unfortunately memory consuming) algorithm for generating all prime numbers up no n:
 
 
$n = 100; //this is the upper limit
 
for ($i = 2; $i <=$n; $i++){
$primes[] = $i;
}
 
foreach ($primes as $num){
if ($num != 1){
[...]

Live RSS Feed page in Wordpress

Iko has an idea of showing Live RSS feeds in Wordpress Pages. Here is my solution to accomplish this task.
Wordpress supports Page templates, on which this solution is based.

Locate page.php in your template’s direcotory.
Copy the file and rename it to something like rsspage.php, and then open it for editing
Add or modify header comment of [...]