Print array elements recursively

Few minutes ago just got a tweet from phpfour (Emran Hasan) that his company is looking for PHP developers. I just visited the announcement page of their site and clicked the apply online button just for testing. There I saw an array written in PHP to solve it. It looked interesting to me and just wrote code for it. Here it is:

<?php
$array = array(
			array(141,151,161),
			2,
			3,
			array(101, 202, 303),
			"php",
			"5"
		);

/**
 * print array elements recursively
 *
 * @param array
 */
function recurse ($array)
{
	//statements
	foreach ($array as $key => $value)
	{
		# code...
		if( is_array( $value ) )
			recurse( $value );
		else
			echo $key . ' => ' . $value . '<br>';
	}
} // End recurse

recurse($array);

/*
output
0 => 141
1 => 151
2 => 161
1 => 2
2 => 3
0 => 101
1 => 202
2 => 303
4 => php
5 => 5
*/

It’s Fun :D

Tags: ,

WordPress Plugin: GAF affiliate widget

Hello there, another wp plugin from me ;) . I was thinking to be a Freelancer.com affiliate (previous GetAFreelancer) and  looking for some wordpress widget as I want to show the links in my blog sidebar. I found a plugin built by Masnun bro, but it gets related projects from freelancer.com according to your post and shows below of your post . So i thought, why i don’t I built one before anyone creates before me? :P . So here is the plugin screenshot:

gaf_widget

Widget setting screenshot

So i don’t need to describe what to do after installing the plugin, right? It’ll show the selected links to your sidebar like this:

Displaying links from freelancer.com

So why don’t you add this plugin to your blog and make some money? :D

punBB extension: Post Share

Showing links in every post

Hey folks, in a short time i’ve made some punbb extension. Here is another, it’s for sharing post. It inserts share button in every post, here is the screenshot:

You will find the configuration at Administration → Settings → Features

Administration Area

Enjoy :)

punBB extension: We miss you!

Just wrote a punBB plugin for Projanmo Forum and now sharing with the community. The plugin describes it’s uses. You will find the configuration at Administration → Settings → Features Here is the screenshot:

Download: We miss you

Requesting bug report :)

punBB extension: Login with ID

Just wrote an another punBB plugin for Projanmo Forum.

In normal uses, everyone sign’s in with username and password. But for a special purpose, i needed to login with user ID and password. Because, when the username is in a complex script language like Bangla and you want to login from the mobile and you don’t have Bangla writing system in your mobile, this feature comes in action.

This extension is written for mobile users actually. When you will visit the forum from mobile, you will be redirected to the login screen containing user ID and password.

Download: Login with ID

Enjoy!!! :D

Bangla date as a PHP class

I have worked with Bangla date a long time ago. The first initiative was to make a extension for forum engine punBB. After that, i made a javascript widget to display Bangla date in any site. The third initiative was to make a facebook application that shows current Bangla date to your facebook profile.

I always wanted to publish this as a PHP Class but never got that chance to do so. After a long time i worked with Bangla date today and finally created a PHP Class to use it anywhere by anyone. Sorry for the late.

Usage:

<?php
include_once 'class.banglaDate.php';
$bn_date = new BanglaDate(time());
$date = $bn_date->get_date();
?>

You will get an array of converted date in Bangla.

A few things needed to know. Bangla date counted or changes after the sun rise. That means, where English date changes at 12′O clock at the night, Bangla date changes at the morning after the sunrise.

Class Constructor:
This class constructor has 2 parameters. The first one in timestamp and the second one is the hour of changing the date. If you want to change the Bangla date like English at 12’0 clock at the night, you should use $bn_date = new BanglaDate(time(), 0). But if you want to change the date at 6′O clock at the morning, use as $bn_date = new BanglaDate(time(), 6). If you don’t pass the second parameter, the default value is 6. Use as you like.

After Creating the class object, you can set another date using set_time() like $bn_date->set_time(time(), 4);

Bangla Date class on PHPClasses.org

Grab your Google Buzz Status

Here’s how you can get your google buzz status with php. Just put your google username at the right place and do whatever you want.
We have used simpleXML to parse the google’s RSS feed for every user. :)

<?php
$user = "<username>";
$url = "http://buzz.googleapis.com/feeds/".$user."/public/posted";
$data = file_get_contents($url);
$xml = new SimpleXMLElement($data);

$status = $xml->entry[0]->summary;
$time = date('D j M Y g:i a', strtotime($xml->entry[0]->published));
echo "Status: $status <br />";
echo "Time: $time";
Tags: , , ,

Create your own twitter image signature

Many days ago i built two image signature as my forum signature. One of the signature shows the latest post from my blog and another shows my latest twitter update. I was inspired to do that signature by seeing Shiplu Vai’s signature. Originally he was using them and i copied the concept :D

Anyway, here is my latest blog post signature Blog Update Signature and here is my twitter signature Twitter image signature

I will show you the process to create your own twitter image signature like me.

1. At first we will get the latest twitter update by this

<?php
$username = "tareq_cse"; //Twitter Username
$url = "http://twitter.com/statuses/user_timeline/$username.json?count=1"; //json request url
$json = json_decode(file_get_contents($url));
$status = $json[0]->text; //get the status from array/object

2. Now we will get the time distance from now and the twitted time and will format it
Read the rest of this entry »

Sending mail with Gmail’s SMTP server with fsockopen

Today i was trying to find a way to send mail from my localhost (xampp) with Gmails SMTP server. I found some code in popular and also fastest forum engine – punBB.

I got the codes and did some cleanup for working fine as an external script. Here is the codes -

<?php

//this functin processes the server return codes and generates errors if needed
function server_parse($socket, $expected_response)
{
	$server_response = '';
	while (substr($server_response, 3, 1) != ' ')
	{
		if (!($server_response = fgets($socket, 256)))
			echo 'Couldn\'t get mail server response codes. Please contact the forum administrator.', __FILE__, __LINE__;
	}

	if (!(substr($server_response, 0, 3) == $expected_response))
		echo 'Unable to send e-mail. Please contact the forum administrator with the following error message reported by the SMTP server: "'.$server_response.'"', __FILE__, __LINE__;
}

//
// This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com).
// They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards.
// -------> This message is from punBB developer
//
function smtp_mail($to, $subject, $message, $headers = '')
{
	$recipients = explode(',', $to);
	$user = '<your mail id>';
	$pass = '<your password>';
	$smtp_host = 'ssl://smtp.gmail.com';
	$smtp_port = 465;

	if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15)))
		echo "Could not connect to smtp host '$smtp_host' ($errno) ($errstr)", __FILE__, __LINE__;

	server_parse($socket, '220');

	fwrite($socket, 'EHLO '.$smtp_host."\r\n");
	server_parse($socket, '250');

	fwrite($socket, 'AUTH LOGIN'."\r\n");
	server_parse($socket, '334');

	fwrite($socket, base64_encode($user)."\r\n");
	server_parse($socket, '334');

	fwrite($socket, base64_encode($pass)."\r\n");
	server_parse($socket, '235');

	fwrite($socket, 'MAIL FROM: <example@gmail.com>'."\r\n");
	server_parse($socket, '250');

	foreach ($recipients as $email)
	{
		fwrite($socket, 'RCPT TO: <'.$email.'>'."\r\n");
		server_parse($socket, '250');
	}

	fwrite($socket, 'DATA'."\r\n");
	server_parse($socket, '354');

	fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");

	fwrite($socket, '.'."\r\n");
	server_parse($socket, '250');

	fwrite($socket, 'QUIT'."\r\n");
	fclose($socket);

	return true;
}

// Send the mail
if(smtp_mail('example@gmail.com', 'Hi! Test Mail', 'This is a test mail from xampp with fsockopen()'))
{
	echo "Mail sent";
}
else
{
	echo "Some error occured";
}
?>
Tags: , , ,

বাংলা তারিখ ভুলে যান? আর ভোলার চান্স নাই

বাংলা তারিখ নিয়ে প্রথমে কাজ করেছিলাম প্রজন্ম ফোরামের জন্যে। সেখানে হেডারে প্রতিদিনের বাংলা তারিখ দেখানো হয়। এরপর করলাম একটা জাভাস্ক্রিপ্ট উইজেট, যেটা দিয়ে আপনি আপনার যেকোন সাইটে বাংলা তারিখ যুক্ত করতে পারেন। অনেকদিন ধরেই চিন্তা করছিলাম ফেসবুকের জন্যে একটা অ্যাপ্লিকেশন বানালে মন্দ হয় না, কিন্তু সময় আর করে উঠতে পারিনি।

ফেসবুকে বাংলা তারিখ

ফেসবুকে বাংলা তারিখ

এই অ্যাপ্লিকেশন দিয়ে আপনি আপনার ফেসবুকের প্রোফাইলে আজকের বাংলা তারিখটি দেখাতে পারবেন। অ্যাপ্লিকেশনটি রয়েছে এখানে http://apps.facebook.com/bangladate/