php

recent posts related to the php programming language

A PHP database metadata example

PHP database FAQ: How do I access the metadata for a database in PHP? That is, for a given database, how do I list the database tables, and fields for those tables?

Solution: I just started this script a little while ago, but even with my limited knowledge of PHP it was very easy to get access to the database metadata, including the database tables and the fields in each table.

PHP preg_match regex examples

PHP regex FAQ: Can you share some PHP regex examples using the PHP preg_match function?

For a recent PHP program I was writing, I experimented with the PHP preg_match function and some regular expressions, trying to get the behavior I was looking for. Now that they're working properly, I thought I'd share two simple examples of my "PHP regex" preg_match examples/experiments.

PHP Zend starter applications

I'm going to be starting a new PHP project later this week, and as I don't like to reinvent the wheel, I've been looking around for some decent PHP starter applications, i.e., PHP skeleton applications.

As I've looked around for PHP starter projects, this starter application from Grover Ponders looks the best. It seems well-organized, and you can just download a tar.gz file and get to work.

A simple PHP form example

PHP form FAQ: Can you share an example of a very simple PHP form (a self-processing PHP form)?

Still trying to catch up on a lot of PHP examples I've written but never published, here's the source code for a simple PHP form example. This form posts back to itself, and while I'm generally not a fan of that coding approach, I have used it from time to time for simple tasks.

A simple PHP form example

Here's the source code for this simple PHP form example:

A PHP cheat sheet (reference page)

PHP cheat sheet FAQ: Can you share a PHP cheat sheet?

This page is a PHP cheat sheet, but a different kind of cheat sheet. As I go deeper and deeper down the PHP rabbit hole, I found that instead of an over-simplified PHP cheat sheet, I wanted a "starter" page that will point me in the right direction when I'm looking for a PHP function for a task. For instance, if I can't remember how to add an element to a PHP array, I want to be able to search this page and find that easily.

PHP printing - How to print variables in a PHP string

Again, nothing major here, just a quick example of how to print variables in PHP, particularly how to print variables in the middle of a PHP string. When you first get started programming in PHP, how to print variables in a PHP string is a common question, so I thought I'd share some examples here.

There are many ways to print variables in a PHP string, but these are some of the most common approaches:

A MySQL PHP update query example

Nothing major here, just an example MySQL PHP UPDATE query (really, a PHP SQL UPDATE query example that happens to use a MySQL database). For all the things I've done lately with PHP, I think this is the first PHP update query I've written, and I wanted to put an example out here so I can find it easily later.

So, with no further ado, here is a simple MySQL PHP update query example:

PHP include syntax examples

PHP FAQ: Can you show an example of how to use the PHP include syntax? Also, can you show an example of how to include HTTP content into a PHP script?

PHP include syntax to include a file

Sure, I just used the PHP include statement in developing a Drupal theme, and a simple form of the PHP include syntax to include a file looks like this:

<? include 'google-analytics.inc' ?>

This includes the contents of the file named "google-analytics.inc" into my PHP page output.

PHP random number examples (rand function)

PHP random number FAQ: Can you show an example of the PHP random function?

Sure. To create a random number in PHP, just use a line of code like this:

$r = rand(1,10);

That will generate a random number from 1 to 10.

Real-world PHP random number example

Next, here's a snippet of PHP code that shows how to create a random number in PHP in some real-world code:

PHP args - How to read command line arguments in PHP

PHP command line args FAQ: How do I read command line arguments in PHP?

Answer: You just need to access the PHP argv array, as shown in this example:

Syndicate content