php

recent posts related to the php programming language

A PHP char_at function

PHP FAQ: Is there a PHP char_at or charAt function, like there is in other languages?

No, there isn't, but you can easily mimic a PHP charAt function like this:

$char = $my_string{4};

That's equivalent to having a charAt function like this:

$char = charAt($my_string, 4);

or this:

A Smarty templates object array example

Smarty templates object array FAQ: How can I display an array of objects with Smarty templates?

I just wasted about thirty minutes trying to figure out how to display an array of objects with Smarty templates, so I thought I'd share the solution here. I'll include my PHP class, some of the PHP logic that builds the Smarty variables (my Smarty object array), and then a portion of the Smarty template that displays my PHP object array.

PHP cannot redeclare function error message

PHP function FAQ: Help, I'm getting a PHP cannot redeclare function error message, how do I fix it?

Assuming you don't really have two PHP functions defined with the same name, this "cannot redeclare" function error message is usually caused by using the require or include functions to include the same common file (and therefore its functions) more than once.

A PHP "select from where in" query example

If you ever need the source code for a PHP "SELECT FROM foo WHERE id in (1,2,3)" example, I hope the following PHP function will be a decent example to work from. I turned a given list of database table id values into a CSV list, then use that string in a "SELECT FROM ... WHERE ... IN ... (list)" SQL query.

I'm not going to explain it today, but I will share the PHP source code for your reading enjoyment (and problem solving).

A PHP array to CSV string example

PHP array to CSV FAQ: How do your convert a PHP array to a CSV string?

Converting a PHP array to a PHP CSV string is so easy, it actually felt like I trick question when I just found the answer in the PHP docs.

In my case, I just had a PHP array named $tags, and I wanted to convert it to a PHP CSV string. To do this, all I had to do was use the PHP implode function, like this:

PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

PHP FAQ: What is the PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in error message, and how do I fix it?

I just ran into this this "mysql_fetch_array() expects parameter 1 to be resource, boolean given" error message, and learned that it's because there's something wrong with my SQL query.

Language-independent CRUD generator: Java Dao and View template examples

As I continue the development of my language-independent CRUD generator application, I thought I'd share a look at a Java Dao class template that I worked on this morning, as well as two simple JSP view templates I created.

A Java CRUD generator example

I'm still spending a couple of hours a day working on my Java CRUD generator. Technically, because this is all driven by templates, this is also a PHP CRUD generator, and a Python CRUD generator, and in general a programming-language independent CRUD generator, but at the moment it seems easiest to refer to it as a "Java CRUD generator", so I'll call it that for the moment.

How my CRUD generator works

In today's update I'd like to show you how this works. In short, you start with a database table like this one:

CakePHP naming conventions

CakePHP naming conventions FAQ: Can you share some examples of the CakePHP naming conventions, specifically the CakePHP model, view, and controller naming conventions?

As I get back into the CakePHP development world, I wanted to make a little CakePHP naming conventions reference page, showing examples of the standard CakePHP naming conventions for CakePHP model, view, and controller elements.

PHP array - How to loop through a PHP array

PHP array FAQ: How do I iterate (loop) through a PHP array?

Answer: The easiest way to loop through a PHP array is to use the PHP foreach operator. If you have a simple one-dimensional array, like the $argv array which lets you access command line arguments, you can loop through it like this:

Syndicate content