php

recent posts related to the php programming language

How to use a here document in PHP

PHP here document FAQ: How do I create a here document in PHP?

If you ever need to use a "here document" in PHP, here's a short example of the PHP here document syntax:

<?php

print <<< END
Four score and seven years ago
our fathers set onto this continent
(and so on ...)
END;

?>

I believe the closing tag you use ("END" in my case) must begin in the first column. This is typical with here document syntax, but I haven't tested it in PHP.

Drupal and CakePHP - Why so many arrays?

As a relative newbie to both Drupal and CakePHP, I see the same programming style in both applications, and I'll call this style "programming in arrays of arrays". That is, anywhere I would normally use an object in Java, the Drupal and CakePHP developers have used an "arrays of arrays" to store data.

Let's look at some source code examples so I can compare their "arrays of arrays" approach to an OOP approach.

A PHP script to send email with an attachment

PHP email FAQ: How do I send email from a PHP script? (Including sending email with an attachment.)

Continuing with my initiation into the PHP programming world, I just finished developing a PHP script to send a mail message with an arbitrary attachment. (I write 'arbitrary' there because a lot of the example PHP mail scripts I've seen focus on attaching an image, and I'm not really familiar with MIME types yet, and "image/jpg" wasn't working for my needs.)

PHP - Strip unwanted characters from a string

PHP string strip FAQ: How can I strip unwanted characters from a PHP string? (Or, How can I delete unwanted characters from a PHP string?)

Here's a quick PHP preg_replace example that takes a given input string, and strips all the characters from the string other than letters (the lowercase letters "a-z", and the uppercase letters "A-Z"):

A PayPal PHP IPN example

If you're looking for a PayPal IPN example written in PHP, I believe the following code works okay. It's based on the PayPal PHP IPN example (from the PayPal developer site), but I fixed some bugs from their example, added an alternate PHP socket example so you don't have to use SSL to connect to PayPal, and added more variables to the script.

CakePHP, PHP, and LAMP developer jobs

Having learned a lot about PHP and CakePHP lately, I was wondering what the job market looks like for CakePHP developers these days, so I've been poking around various websites lately to see what's going on.

Careerbuilder.com shows a few jobs for CakePHP developers, with salaries in the wide range of $50K to $100K per year. Digging into the descriptions, some of those jobs are actually for Rails developers, PHP developers, and LAMP developers.

Comments in PHP - PHP comment syntax and examples

It's funny, when I first started working with PHP, the first thing I wanted to know is "What is the PHP comments syntax?" (It reminds me of learning to ride a motorcycle, where the first thing you want/need to learn is how to stop.)

Fortunately, if you have a Unix/Linux and/or C programming background, the PHP comment syntax will seem very familiar, and I'll share some simple PHP comment examples here.

CakePHP SQL debug - Configure the CakePHP debug output setting

CakePHP SQL debug tip: If you're a CakePHP newbie, one of the surprising things about seeing your first CakePHP view pages is seeing the CakePHP debug output (the SQL debug output) at the bottom of your view pages. It's definitely a nice feature for when you're learning CakePHP, and also for any time you're trying to understand what queries CakePHP is running for you, but it's a surprise at first.

Setting the CakePHP page title

CakePHP page title FAQ: I'm still a CakePHP newbie, but I just figured out how to change the page title on my CakePHP view pages (i.e., the HTML TITLE tag on my view pages), so I thought I'd share that process here.

Setting the CakePHP page title

The first step in setting a CakePHP view title is to set the pageTitle variable in your CakePHP controller method. Here's an example where I set the page title in a typical CakePHP controller index method:

CakePHP find and the SELECT BETWEEN query syntax

In an effort to get more CakePHP find query examples out into the world, here are two examples of how to perform SQL "SELECT BETWEEN" queries using the CakePHP find method.

In my first find query example, I'm trying to find all the records from the logfile_records database table where the date column is between the two dates specified:

Syndicate content