php

How to use a switch case 'or' in PHP?

is there such thing (in PHP anyway) for an OR operator in a switch case? something like.. switch ($value) { case 1 || 2: echo 'the value is either 1 or 2'; break; } ...

Why am I getting HTML in my MySQL export to CSV?

I know this question has been asked before, but I ran into a problem. Oddly enough, when I execute this function, it includes the html of the page that the link you select to execute the function. function exportCSV($table) { $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { ...

PHP Dynamic Pagination Without SQL

I've got a script that dynamically calls and displays images from a directory, what would be the best way to paginate this? I'd like to be able to control the number of images that are displayed per page through a variable within the script. I'm thinking of using URL varriables (ie - http://domain.com/page.php?page=1) but am unsure how...

How can I make part of a Joomla template editable via the CMS interface?

Title says most of it. I have inherited a Joomla site and the client wants part of the main template (a feature-type box) to be editable via the Joomla backend. I guess really it is a content item that never gets displayed as its own page, but as a part of all pages. Is that possible? Thanks. EDIT: By editable, I mean as a piece of...

Best practices for getting cross-site JSON responses to POST?

I'm working on an intranet with several subdomains. I have control over each subdomain, so security of cross-site requests is not a concern. I have PHP scripts with JSON responses I'd like to call from multiple subdomains without duplication. For GET requests, I can do this with AJAX and JSONP, but that doesn't work with POST requests. S...

PHP development environment best practices

There are so many options when it comes to PHP development environments and you have to piece it all together yourself. I'm wondering if someone has come up with what they think is the ideal setup that gets out of your way and lets you develop. Right now I use vim and svn from the command-line. I write scripts to manage builds but I'm...

Great Eclipse Set-up for PHP Development

I use Eclipse PDT, Subclipse, viPlugin and JSEclipse for my PHP and JavaScript development. This gives me quite a nice environment, but I wonder what else is out there that might be even better. What plug-ins have you installed into Eclipse to create your great set-up for developing using PHP and JavaScript? Which features do you find m...

Converting a Google search query to a PostgreSQL "tsquery"

How can I convert a Google search query to something I can feed PostgreSQL's to_tsquery() ? If there's no existing library out there, how should I go about parsing a Google search query in a language like PHP? For example, I'd like to take the following Google-ish search query: ("used cars" OR "new cars") -ford -mistubishi And turn ...

Replacing spaces using regex in php

I'm pretty new to regular expressions. I have a requirement to replace spaces in a piece of multi-line text. The replacement rules are these: Replace all spaces at start-of-line with a non-breaking space ( ) Replace any instance of repeated spaces (more than one space together) with the same number of non-breaking-spaces Single s...

What is the best web-based File Explorer?

I would like to know what you think is the best web-based File Explorer to manage files in a remote server through HTTP / Web. It would be preferable to have PHP or Flash technology, but any good suggestion would do. More generally, how would you allow someone to manage files on a remote server with HTTP being the only open outgoing po...

Advice on Splitting Up an Application

I currently have a web app that has 3 front ends (depending on what URL you go to) that shares very little code between the 3 front ends. My directory structure looks like this: \app1 \includes \html \app2 \includes \html \app3 \includes \html \crons \libs \logs \setup \db \shared \globalFunctions \ol...

Using htmlentities in a string

Hi. I know I should be using htmlentities for all my form text input fields but this doesn't work: <?php echo "<tr> <td align=\"right\">".Telephone." :</td> <td><input type=\"text\" name=\"telephone\" size=\"27\" value=\"htmlentities($row[telephone])\"> Inc. dialing codes </td> </tr>"; ?> I...

PHP Opt-Code Caching/Zend Acceleration and include_once vs. require_once

I have a colleague who is looking into Opt-Code Caching/Zend Acceleration (I've always assumed these are the same thing) for our PHP based application. His Benchmarks appear to indicate that we're NOT seeing a performance benefit if we include our (large) class libraries with require_once, but we DO see the performance benefit when usin...

Does PHP have threading?

I found this PECL package called threads, but there is not a release yet. And nothing is coming up on the PHP website. ...

Compile regex in PHP

Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages can do this -- Java, C#, Python, Javascript, etc. ...

Finding blank areas of an image file using ImageMagick

I need to be able to determine if a part of an image (outside of predetermined crop marks) contains any image content. Is there a way with ImageMagick (specifically the php interface) to do this? Scenario: The canvas is 8.5x11 with .5 in margins on the top, left, and bottom edges and a 1 in margin on the right edge. The image needs to...

Remove repetitive, hard coded loops and conditions in PHP

I saw this question asked about C# I would like an answer for PHP. I have some old code that has 4 pages of foreach loops and conditions which just makes it hard to read and follow. How would I make this more OO? I was thinking of using SPL Functions but don't fully understand whats involved yet. ...

Safe PHP Template Engines

What are some PHP template engines that offer a simple, short syntax? What we're looking for is: Conditionals (if/else) Foreach loops Variable replacements Able to create custom tags (i.e., for URL generators) We need it to be secure because the applications are being run on our own servers, but we still want people to be able to edi...

PDO Prepared Statements

Is there a way to get the raw SQL string executed when calling PDOStatement::execute() on a prepared statement? For debugging purposes this would be extremely useful. ...

Restricting file downloads

Hi, I'm currently creating a website for a client that will basically involve selling various files. This is obviously a really common thing to do, which is making me feel kind of foolish for not thinking of a method for doing it. Once the purchase has been made the customer should be taken to a page containing the download link, as wel...