PHP Multilanguage Site Using Arrays

PHP Multilanguage

Here we can develop multilanguage site with the use of arrays

So, here we go:

First of all we need a configuration setting inside our script’s config.php file. For the sake of our example, we’ll add a manual variable change:

// language settings
$lng = ‘en’;

Next, our header file, dubbed header.php (could be head.php or top.php in your script) will contain these lines:


You now, obviously, have to create a languages directory and create a new file called en.php. This file will hold our array of words and expressions:

@Package: My Multilanguage Script
@Language: English (English)

$lang = array();

$lang[‘REGISTER’] = ‘Register’;
$lang[‘USERNAME’] = ‘Username’;
$lang[‘PASSWORD’] = ‘Password’;
$lang[‘LOGIN’] = ‘Log in’;
$lang[‘LOGOUT’] = ‘Log out’;
$lang[‘DASHBOARD’] = ‘Dashboard’;

Notice how I tried to keep the array index name as close to translation as possible. For example, you’ll have the string “Separate tags with commas” as $lang[‘SEPARATE_TAGS_COMMAS’]. It’s easier after a couple of months when you’ll make changes.

Also, try to keep consistent naming of your language files, such as fr.php, de.php, ru.php, cn.php.

Now, call in you script . It will display “Register”, just as you translated it in your language file.

Scrolling div with Javascript

You can scroll div with javascript. You need to have one mainContainer which will contain the child for it. eg.

I will have mainArea div with child div myReport.

You need to fixed the height for the mainArea div with style

Now your div can scroll, You now need to write one line code in any javascript function

function scrollMainArea()
document.getElementById(“mainArea”).scrollTop = 0;

This will move your myReport div to show the top portion of your division.

Zend Framework: Storing session data in database

The reason behind saving session data in database is that data become more secure and can be easily retrieved later on.
Let’s look how simple and easy it is to save session data in database using Zend_Session_SaveHandler_DbTable in Zend Framework.
1. Creating database table for holding session data
Before writing code you will need to create a table in the database for holding session data. Execute the following query for this purpose.
CREATE TABLE `session` (
`id` char(32),
`modified` int,
`lifetime` int,
`data` text,

2.Making necessary configuration in your bootstrap file.
You will only need only few lines of code in your bootstrap file.
After making database configuration in your bootstrap file, write the following code.
$config = array(
‘name’ => ‘session’,
‘primary’ => ‘id’,
‘modifiedColumn’ => ‘modified’,
‘dataColumn’ => ‘data’,
‘lifetimeColumn’ => ‘lifetime’

In the $config array we tell the name of the table that will store the session information, primary key of the table, column that will store the session modification timestamp(*nix timestamp), column that will store the session data, and the column that save the information about how long the session will last.

After defining this configuration array we call setSaveHandler() method- static method, of the Zend_Session. This setSaveHandler() method accept Zend_Session_SaveHandler_DbTable object. Zend_Session_SaveHandler_DbTable take configuration array as an argument.

We have now done all the necessary configuration. The only thing we will need to do now is to start our session. Session can be started in the bootstrap file, however it’s not necessary for the session to be started here. You can start it in any controller you needed.

Anywhere in your controller, write
$namespace = new Zend_Session_Namespace();
$namespace->name = “Viral”;

and check your session table. The table will not only hold session id, but also the modified timestamp of when session was modified, life time of the session and the session data in special format.
Try it. Its really cool.

Zend Framework SQL Joins Examples

You may have custom of using advanced queries. It often requires writing complex queries if you are working on enterprise, large scale web application(s).
The use of joins can never be ignored.
Zend Framework developers have done tremendous job by providing simple method for implementing joins.
Lets look some examples of different type of joins.
Before discussing joins lets consider we have two tables, “authors” and “books”.
These are associated with author_id.

1. Inner Join

The simplest query will be
$select = $this->_db->select()
->where(‘where condition here’)
->order(‘column name ASC/DESC’);

2. Left Join

$select = $this->_db->select()
->where(‘where condition here’)
->group(‘group by column name here’)
->order(‘column name ASC/DESC’);

3. Right Join

$select = $this->_db->select()
->where(‘where condition here’)
->group(‘group by column name here’)
->order(‘column name ASC/DESC’);

4. Full Join

$select = $this->_db->select()
->where(‘where condition here’)
->group(‘group by column name here’)
->order(‘column name ASC/DESC’);

5. Cross Join

$select = $this->_db->select()
->where(‘where condition here’)
->group(‘group by column name here’)
->order(‘column name ASC/DESC’);

Once you write these queries, you can fetch a single row or multiple rows as

How to Charm Your Way Through Life

Charismatic people are those who have the ability to inspire and influence others. Such people often have an aura of magnetism surrounding them.

However, Charisma is not a magical power and can be acquired by anyone who wishes to. Following are the suggestions which can help you build up the charismatic factor in you.

Find Ease in Yourself
In order to feel charismatic, you need not incorporate any artificial swagger or machismo. You just have to feel comfortable in your own skin and emphasize your real self with others as well.

No Bargain
While trying to maintain their self-assertion, people often come across as aggressive. This, however, does not mean that you hide your individuality. You should find the ability to draw a line between assertion and aggression.

Accept Your Flaws
Charismatic people never fail to compliment someone or embrace their own weaknesses. Similarly, you should never shy away from admitting your mistakes. It not only increases your charm quotient but also makes you a better person.

Be Full of Life
Contrary to the pre-conceived notion that charming people have to be intelligent or witty, it is the good-humouredness of a person that can more hearts. So, don’t try too hard to be too scholarly; just go ahead and have fun with the people around you.

Be Aware of Yourself
The key to becoming a charming person is to know yourself and your beliefs as it reflects in personality. A person who is unsure of himself fails to strike a positive impact on others. Discover yourself and let the light of your self-awareness shine upon others too.

Practice Makes Perfect
Being charismatic is a skill which which everyone can learn. You cannot expect to wake up one morning as the most charismatic individual on the planet just because you desired so. It has to be built over time and with precision. After all, nothing comes easy in life.

How to Get Over with Negative Thoughts

Our thoughts are the doorway of our emotions. “I’m completely stuck in this” – if such thoughts crop up in your mind quite often, it’s time to give a serious thought to the things going wrong. A possible reason can be the responsibility of playing of several roles in life.

Many times we experienceinsomnia, mood swings, emotional turmoil and uneasiness while carrying out various duties in our lives. This can further make you passive on many fronts in life.

We then lose all our positive energy and become the storehouse of negative energy.

Here are a few tips of regaining the lost positive energy in life:

Take Out Time for Yourself: Try and do a division of your heavy workload. Make a list of tasks which can be split into smaller chunks. If there are some tasks which you carry out regularly but at the back of your head you realise they aren’t really important, give them up. Try and learn the art of time management. Make attempts to strike a balance between your personal and family life.

Bad Times would Eventually Go Away: Downbeat circumstances can become a cause of sorrow. But bear this in your mind that this time would eventually be over. Try and see if any benefits can be extracted from such harsh times. This would promote optimism in you.

Good Company: Try and avoid the company of people whose favourite pastime is exploring negativities in others. This can only aggravate your problem.

Think Positive: Don’t let thoughts like: “I’m trapped”, “things are never going to change” etc. cloud your head. Easier said than done but you can at least give it a try.

At your Workplace: If you’re finding it difficult to handle things in your office, do not hesitate in walking up to your boss and discussing things with him. These days many companies provide counseling to their employees.

Leisure Activities: Though clichéd but activites like watching movies, listening to music, gossiping, travelling can actually help you overcome negativities in your life.

Getaways: If you’re stuck in the din and bustle of your city life, it’s time to go for a nonchalant break. Plan getaways to hills, jungles, beaches et al (there’s no point going to just another city for that would not help you escape from the usual uproar). You would feel rejuvenated and. Some personal experience here. I recently went for holidaying in the Corbett jungles. After coming back I felt refreshed and more optimistic.

Eat Healthy: Eating healthy food is a key to not just remain physically fit but also to attain good mental health. 

“If it is to be, it is up to me!”

A set of ten two-letter words to help from a new you

Have you heard of the rather unique funeral held in an office in New York some years ago? As employees of the firm came in to work one Monday morning, they were greeted by a solemn notice at the entrance: “The person responsible for inhibiting your growth died yesterday. The body has been placed in the cafeteria, till 2 pm today.”

Sad to think a colleague had passed away, and curious who the person might be, the employees trooped into the cafeteria to pay their last respects. A crowd of company staff had gathered inside. ‘Who is this chap who has been hindering our growth?’ each wondered, as they walked up to the coffin to take a dekko. One by one, as each person took a look inside the coffin, there was shocked silence – and a look of disbelief.

Inside the coffin was a mirror. And below it was a placard on which was written: “There’s only one person who can set limits to your growth. And that’s YOU.” Now that’s a message we would all do well to remember.

When we find ourselves falling short of the success we think we deserve, we often blame our bosses, our employers, the industry, or the current favourite – the recession! Everyone and everything, in fact, except ourselves. For things to change in your life, you don’t need to change your job, or your company or your town. You only need to change yourself. Start now. Adopt a new philosophy for your life. Tell yourself the magic phrase: “If it is to be, it is up to me!” It’s not often that you can get a set of ten two-letter words to form one whole sentence. And no ordinary sentence but one, which has the power to become a life-changing philosophy for you, for me and for all of us: “If it is to be, it is up to me!” Just say it to yourself, believe in it, and see the difference.

The power to change our lives and chart our future lies within each of us. Resist the temptation to blame others for your plight. When you blame other people, you take away your inherent power to change. You weaken yourself. But by taking responsibility, you empower yourself to change your fortunes. And that one act – taking responsibility for yourself – is really what separates winners from losers.

Have you ever seen sailing boats wander into the sea? They all take off from one place, around the same time, and yet reach different shores. Why is that? The winds are the same. The water currents too are the same for all the boats. Yet, they reach different destinations, because, where the boat will reach is determined not by the direction of the wind, but by the set of the sails.

Our lives are like that too. So stop blaming the winds of your company policy or the currents of the economy. Stop worrying that you did not go to a premier B-School, or that you grew up in a non-English-speaking home. Take charge of your life. Change your mindset and get your thinking right. To reach your goals, it’s important to set your sails properly. For things to get better, you need to get better. Need new skills? Invest in training yourself don’t wait for your employer to do it. I find it puzzling that while young people spend money on trendy new clothes, and on new cellphones and on the monthly visit to the beauty salon, they want the company to spend money on training them, on making them better employees, smarter people. ‘Training myself is not my responsibility’ seems to be the general dictum!

For things to change, we must change our beliefs, and our mindsets. Do yourself a favour. Stick this ten-word aphorism on your bathroom mirror: “If it is to be, it is up to me!” And wake up to a new you.