php

Checking if array is multidimensional or not?

What is the most efficient way to check if an array is a flat array of primitive values or if it is a multidimensional array? Is there any way to do this without actually looping through an array and running is_array() on each of its elements? ...

PHP's SPL: Do its interfaces involving arrays cover all array properties?

Would it be possible to write a class that is virtually indistinguishable from an actual PHP array by implementing all the necessary SPL interfaces? Are they missing anything that would be critical? I'd like to build a more advanced Array object, but I want to make sure I wouldn't break an existing app that uses arrays everywhere if I s...

Can you recommend Peformance Analysis tools for PHP?

Can anyone recommend some useful performance analysis tools for PHP scripts? Anything that could help me find problematic or unusually slow blocks of code, details about execution time, etc. would be really helpful. I know there are tools out there, but I'm wondering what people recommend as being the most useful and well-designed. ...

Easy way to embed svn revision number in page in PHP?

Notice in the bottom right hand corner of this page it has the SVN revision id? I'm assuming that's dynamic. I'd love to add that to some of my sites, just as a comment in the source to make sure code pushes are going through. NOTE: You can also assume that the working directory of the site in question is an svn checkout of the repo in...

Lisp+PHP ?

At the moment I use PHP for almost everything I develop for the Web but its linguistic limitations are starting to annoy me. However, as I developed some practices and maintain some PHP libraries that help me a lot, I don't feel I'd be ready to just switch to LISP throwing away all my PHP output. It could even be impossible on the server...

Unable to access HTTP PUT data in webservice code

All, As part of an application I'm writing I need to have a HTTP PUT webservice which accepts incoming imagedata, which will by analyzed, validated, and added to a local file store. My issue arises after the size validation as the $_SERVER['CONTENT_LENGTH'] has a > 0 value, and this value is identical to the test file size, so I...

Setting PHP variables in httpd.conf?

Hi, I'd like to automatically change my database connection settings on a per-vhost basis, so that I don't have to edit any PHP code as it moves from staging to live and yet access different databases. This is on a single dedicated server. So I was wondering, can I set a PHP variable or constant in httpd.conf as part of the vhost defi...

Closures in PHP... what, precisely, are they and when would you need to use them?

So I'm programming along in a nice, up to date, object oriented fashion. I regularly make use of the various aspects of OO programming that PHP implements but I am wondering when might I need to use closures. Any experts out there that can shed some light on when it would be useful to implement closures? ...

Comprehensive server-side validation

I currently have a fairly robust server-side validation system in place, but I'm looking for some feedback to make sure I've covered all angles. Here is a brief outline of what I'm doing at the moment: Ensure the input is not empty, or is too long Escape query strings to prevent SQL injection Using regular expressions to reject invalid...

Error with bindParam overwriting in PHP

This is a bit of a weird one, and I could well be coding this completely wrong - hence why I've hit the same error twice in two days, in completely different parts of a script. The code I'm using is below: public function findAll( $constraints = array() ) { // Select all records $SQL = 'SELECT * FROM ' . $this->tableName...

Should I be extending this class? (PHP)

I'm creating an ORM in PHP, and I've got a class 'ORM' which basically creates an object corresponding to a database table (I'm aiming for similar to/same functionality as an ActiveRecord pattern.) ORM itself extends 'Database', which sets up the database connection. So, I can call: $c = new Customer(); $c->name = 'John Smith'; $c->sav...

REGEX: Grabbing everything until a specific word

ex: <a><strike>example data in here</strike></a> I want everything inside the a tag, to the end /<a>([^<]*)<\/a>/ It works when there are no additional tags within the <a> tag, but what if there are? I want to know if you can tell it to grab everything up to [^</a>] instead of [^<] only. Doing it with /<a>(.*)<\/a>/ doesn't wor...

Is there a SAPI module for PHP 5 for supporting the thttpd web server?

Hi, Is there a SAPI module for PHP 5 for supporting the thttpd web server? Oddly, the one included on PHP 5.2.6 source is for PHP 4.x. Thanks, Kenneth ...

Loading .sql files from within PHP

I'm creating an installation script for an application that I'm developing and need to create databases dynamically from within PHP. I've got it to create the database but now I need to load in several .sql files. I had planned to open the file and mysql_query it a line at a time - until I looked at the schema files and realised they are...

Standard algorithm to tokenize a string, keep delimiters (in PHP)

I want to split an arithmetic expression into tokens, to convert it into RPN. Java has the StringTokenizer, which can optionally keep the delimiters. That way, I could use the operators as delimiters. Unfortunately, I need to do this in PHP, which has strtok, but that throws away the delimiters, so I need to brew something myself. This...

Is encrypting AJAX calls for authentication possible with jQuery?

I'm fairly new to the AJAX methodologies (I only recently discovered jQuery a short time ago). I am interested to know if there is anyway to authenticate a user on a PHP setup; securely. Does jQuery have any special options to allow use of HTTPS (or any other way to encrypt my ajax call)? Yes, I could very well just post data back to t...

Generate getters and setters (Zend Studio for Eclipse)

Hi!, I'm using Zend Studio for Eclipse (Linux), and I'm trying to generate getter and setters methods in a PHP class. I try to do this: http://files.zend.com/help/Zend-Studio-Eclipse-Help/creating_getters_and_setters.htm but I haven't "Generate Getters and Setters" option in Source Menu, it's missed! Could u help me? Thanks! ...

How efficient is define in PHP?

C++ preprocessor #define is totally different. Is the PHP define() any different than just creating a var? define("SETTING", 0); $something = SETTING; vs $setting = 0; $something = $setting; ...

How to store configuration parameters in SVN?

Like many projects, we deploy to many environments, QA, UA, Developer trunks, etc.. What is the best way to store sensitive configuration parameters in SVN? Or, should you not and just maintain a smaller unversioned file with credentials in it on the server? Mainly, we do not want to expose production credentials to every developer. ...

Php code formatter / beautifier and php beautification in general

Do you know any good tools for nicely formatting messy php code? Preferably a script for Aptana/Eclipse, but a standalone tool will do too. ...