Tag Archives: php

How to get last key in an array in PHP


How to get last key in an array in PHP? Arrays can have lots of elements, some that may not be needed at one point. Let’s say that we need in some cases the last key or last element of an array in PHP, what would you do? A very good solution and clever practice

Convert variable to string in PHP


Convert variable to string in PHP PHP is a loosely typed language and assigns types to variables depending what is assigned to it. Sometimes you will want to transform a given variable into a string format and obtain a similar output with “ToString()” method in Java or .NET. This could be done easily with one of the following

How to explode a string on upper case characters


How to explode a string on upper case characters Problem You have a string with the following value “thisStringMustBeSplittedAfterUpperCase” and you want to obtain every word separately in an array, splitted after upper case. Solution

Output The output of the $chunks array obtained with a var_dump($chunks) will be:

Solution in a function

How to strip all spaces out of a string in php


How to strip all spaces out of a string in php You have a string stored in a PHP variable, and you want to eliminate all whitespaces or spaces from that string with PHP, not only from the beginning or the end of the string. Scenario

Solution for spaces

Solution for whitespaces

How to use PHP namespaces


PHP namespaces Before we dig in into namespaces, we have to understand what they are, and how they are used. A simple analogy can be made between PHP namespaces and a filesystem. They work quite the same and apply the same principle. Imagine the following directory structure:

Everything clear. You have a “foo.txt” file in the

Build multilanguage websites with gettext

Multilanguage Website

Build multilanguage websites with gettext Have you ever tried to build a multilanguage website using php ? Whether you did it or not, you should know that this thing requires some thinking before you start coding. I will present you a very simple, fast and scalable solution for this. What is gettext ? Gettext is a

PHP classes and objects


PHP classes and objects Few days ago I had a talk with a few friends of mine about this topic, and I saw that some people are still misunderstanding the OOP paradigm in programming. So I want to clarify a few things in this article. What is OOP ? OOP stands for Object Oriented Programming and

5 of the best PHP frameworks for programmers

MVC PHP frameworks

A bit about php frameworks This is a topic that is not very well understood  by people who jump into development pool. PHP frameworks help to promote rapid application development, which saves you time, helps build more stable applications, and reduces the amount of repetitive coding for developers. Frameworks can also help beginners to build more

Best practices to optimize code performance in php

php code

Best practices to optimize code performance in php We developers, should search constantly for best practices when writing code. In this article I will focus on how to can write better and faster php code.  Keep in mind also that people get carried away with performance. I personally prefer to design for flexibility first, and worry

Install memcached daemon / Install memcached extension using pecl

A little about Memcached Memcached is a service that allows you to store in memory key-value data like strings or objects, from results like databases queries, API calls and drastically accelerating queries and reducing the load on your server. Memcached is being used by major websites like Youtube, Twitter, Digg, WordPress.com and many many more.

Request an article ←