background preloader

Php

Facebook Twitter

Sorting a Multi-Dimensional Array with PHP. Every so often I find myself with a multidimensional array that I want to sort by a value in a sub-array.

Sorting a Multi-Dimensional Array with PHP

I have an array that might look like this: //an array of some songs I like $songs = array( '1' => array('artist'=>'The Smashing Pumpkins', 'songname'=>'Soma'), '2' => array('artist'=>'The Decemberists', 'songname'=>'The Island'), '3' => array('artist'=>'Fleetwood Mac', 'songname' =>'Second-hand News') ); The problem is thus: I’d like to echo out the songs I like in the format “Songname (Artist),” and I’d like to do it alphabetically by artist.

So I developed a quick function to sort by the value of a key in a sub-array. Plugin de commentaire. Create a REST API with PHP « Gen X Design. Your apps never had it so good One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST.

Create a REST API with PHP « Gen X Design

It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially use nothing more than an HTTP spec that has existed for ages. One of the few things that I give Rails credit for is its well thought-out REST support, both for providing and consuming these APIs (as its been explained by all the Rails fanboys I work with). Seriously, if you’ve never used REST, but you’ve ever had to work with (or worse, create) a SOAP API, or simply opened a WSDL and had your head explode, boy do I have good news for you! So, What on Earth is REST? Before we get into writing some code, I want to make sure everyone’s got a good understanding of what REST is and how its great for APIs.

Requests All APIs need to accept requests. Social Network Style Posting with PHP, MongoDB and jQuery - part 1. Post mechanisms similar to Facebook are nowadays very common within any application.

Social Network Style Posting with PHP, MongoDB and jQuery - part 1

The concept of Post-Like-Comment is familiar to everyone who ever used a social network. In this article, we will learn how to create a similar working model wherein the user will be able to post his status, like posts and comment on them. Laravel - a beautiful PHP framework that does not make me feel stupid. {15 Mai 2012} I may have solid artistic skills, and I also enjoy web development (most of the time), but the sad truth is that I am an awful programmer.

Laravel - a beautiful PHP framework that does not make me feel stupid

I came to web development “the wrong way”, inserting <? Php ? > blocks into my HTML code. Interconnect IT - WordPress Consultants, Web Development and Web Design. Search Replace DB version 3.0.0 (currently a BETA version) allows you to carry out database wide search/replace actions that don’t damage PHP serialized strings or objects with a user friendly interface and experience.

Interconnect IT - WordPress Consultants, Web Development and Web Design

Installation & Use Now acts like a web app! To use the script, download the zip file from below, extract the folder called secret-name-please, renaming it to something secret of your choosing, then navigate to that folder in your browser. The script will automatically attempt to find and populate the database field but you must check that the details are correct and that it is for the database you wish to carry out a search/replace operation on. To see how you can use this tool to aid migrations, check out our article on WordPress migrations or visit the WP Tuts+ article that mentions this script. Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks. I wrote before a guide Howto install Nginx/PHP-FPM on Fedora 20/19, CentOS/RHEL 6.5/5.10, but this guide is just installation guide and many cases Nginx and PHP-FPM basic configuration is good enough, but if you want to squeeze all the juice out of your VPS or web server / servers and do your maintenance work little bit easier, then this guide might be useful.

Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks

These tips are based entirely on my own experience, so they may not be an absolute truth, and in some situations, a completely different configuration may work better. It’s also good to remember leave resources for another services also if you run example, MySQL, PostgreSQL, MongoDB, Mail server, Name server and/or SSH server on same machine. And yes here we go… Nginx Configuration and Optimizing Tips and Tricks Nginx Tip 1. – Organize Nginx Configuration Files Normally Nginx configuration files are located under /etc/nginx path. Remember add following includes at the end of your nginx.conf file: PHP 5.4 is Here! What You Must Know. PHP 5.4 is here; the next major step forward since version 5.3 - keeping PHP 6 (full Unicode support) on hold for now.

PHP 5.4 is Here! What You Must Know

The latest enhancements significantly improve its elegance, while removing deprecated functionality, resulting in a dramatic optimization of the runtime (up to 20% more speed and memory usage reduction). PHP Frameworks comparison matrix (symfony vs cakephp vs zend framework vs CodeIgniter vs Yii) How to access cross-domain data with AJAX using JSONP, jQuery and PHP. I’m guessing that if you are reading this post you have already encountered the problem of the same origin policy with regards to retrieving data with AJAX from urls in other domains than your’s (the requesting domain).

How to access cross-domain data with AJAX using JSONP, jQuery and PHP

This policy, enforced by browsers, means you cannot fetch raw data from other domains with straight AJAX calls. The Problem I Was Trying To Solve (skip this paragraph if you just want the solution) Here’s the situation I ran into. At work, we have a timesheet entry program running on one subdomain, and Flyspray (bug-tracking software) on another subdomain. We wanted to get task descriptions from Flyspray integrated in our employee timesheet notes. Basically, the employee types a Flyspray task # for a given task they are working on, anywhere in their timesheet log entries.

JSONP Circumvents the Same Origin Policy Data returned from an AJAX call in JSONP (JSON with padding) format is designed to solve this problem. Example 1. Smarty 3 extension for Zend Framework / PHP open source snippets / Blog. Update 2010-10-30 Added support for partials using smarty view, clone of view was updatedRemoved dependency on config storage on bootstrap Note:

Smarty 3 extension for Zend Framework / PHP open source snippets / Blog

Templating Engines in PHP. This blog post is not for the faint-hearted!

Templating Engines in PHP

Some people will strongly disagree with me and some others will probably want to kill me at the upcoming Zend Conference. And if starting an argument in the comments can help you feel better, please feel free to do so. If you want to have a more advanced discussion on this topic, vote for my talk at the Zend UnConference. Cross-domain cookies/sessions in Safari and all other browsers. The Problem Safari does not allow cross-domain cookies. In other words, if on X.com, you load an iFrame with contents of Y.com and set a cookie in the iFrame, Safari will not save the cookie. This problem also occurs in IE6/7 but can be resolved by sending a P3P header. The Solution I am not entirely sure why this works, but the cookie gets saved if a post is made to the iFrame.

Here is the code that goes on the remote domain: The contents for startsession.php would be as simple as: To make sure that your site is compatible with IE6/7, always output the following header: [PHP] Les ressemblances à ne pas confondre. Introduction Cette astuce présente plusieurs fonction ou astuces en php qui sont différentes alors que beaucoup de monde croit qu'elles agissent de la même façon. Concaténation ou paramètres ? Avec la fonction echo (ou print), on peut afficher plusieurs variables et chaines de caractères à la suite.

Exemple : Ici, on utilise la virgule entre la chaine de caractères et la variable. Lorsque l'on utilise des points, on apelle ça la concatenation. J'ai testé les deux méthodes, et le passage de plusieurs paramètres est assurément plus rapide. Voici d'ailleurs une page de test ou sont comparés les deux méthodes : Cependant, les virgules ne peuvent être utilisés qu'avec un echo ou un print, contrairement à la concaténation.