php

Efficient PHP auto-loading and naming strategies

Like most web developers these days, I'm thoroughly enjoying the benefits of solid MVC architecture for web apps and sites. When doing MVC with PHP, autoloading obviously comes in extremely handy. I've become a fan of spl_autoload_register over simply defining a single __autoload() function, as this is obviously more flexible if you ar...

How to get detail of the data from database?

Hi to all, Actually I was confused to give the title for this question. I have condition like this. When we get record from database using limit like select * from table_name limit 0,5 we get the data from 0 to 5 and when we use limit 5,10 we get 10 records from 5... Is it possible to display that particular index of the record...

PHP and source control: where to put unit tests, etc?

Hi, I'm using Bazaar for version control, which I'm very happy with. In Bazaar every tree/project in source control is called a 'branch'. Currently I have a 'main' branch for the actual application, and a 'dev' branch which houses some things like unit tests, as well as the user manual, etc. This way, both the app and its associated ...

How do I prevent Php's DOMDocument from encoding html entities?

I have a function that replaces anchors' href attribute in a string using Php's DOMDocument. Here's a snippet: $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHTML($text); $anchors = $doc->getElementsByTagName('a'); foreach($anchors as $a) { $a->setAttribute('href', 'http://google.com'); } return $doc->saveHTML(); The ...

How to invoke js without displaying the code

Hello, I was wondering, I want to plant a JS tracking code (analytics) in a few websites to track their traffic. But I don't want that when viewing the site's source code people will be able to see that I've embedded the JS tracking code there. Is it possible? Maybe by using an Apache/PHP trick? Thanks, Roy. ...

htaccess Authentication with PHP

On the current website I'm working on, I've got a directory of files for users to download which would be really nice to have some security method other than obscurity ;) I was wondering if there's any way to supply login information via PHP to htaccess as though a user were entering it. Alternately, if anyone knows a better way to sec...

Regular expression to change user input

I am doing a search on my database. If the user enters eg. "foo bar" I want to display rows that have both "foo" AND "bar". My SQL syntax looks like this: SELECT * FROM t1 WHERE MATCH (t1.foo_desc, t2.bar_desc) AGAINST ('+foo* +bar*') How can I change the user input "foo bar" into "+foo* +bar*" using a regular expression in PHP? ...

Vim syntax based folding with php

I have downloaded php.vim file, which contains PHP-based syntax information. It should be able to provide syntax based folding, but I can't make it work for some reason. I have set :let g:php_folding 2 and :set foldmethod=syntax but for no avail. I'm pretty sure the file is in right place and is read by vim, since I can do :let g:php_sq...

is_file or file_exists in PHP

Hi there, I need to check if a file is on HDD at a specified location ($path.$file_name). Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP? ...

Is it possible to create a Windows shortcut using PHP?

I'm writing a script to tidy up a bunch of media spread across my hard drives, and it works pretty well so far at home (on my Mac) as I use symlinks in a directory to give the impression that everything is organised in one location, whilst the actual data is spread across the 4 drives. Unfortunately, I have to use Windows at work, and o...

How to start using and developing on Ubuntu Linux?

I am a newbie Linux user who came from 10 years using windows OS, and developing in Microsoft languages. I want to have a good experience in Linux world and developing on it. First, I want to learn how to use this new OS, then how to start developing on it, I am interested in web applications, specially using Java/PHP because I have some...

Can this be a efficent and reliable way to purify user's input?

Hi guys, im wondering about how to set up a clever way to have all my input 'clean', a procedure to run at the begin of every my script. I thought to create a class to do that, and then, add a 2 letter prefix in the begin of every input to identify the kind of input, for example: in-mynumber tx-name ph-phone em-email So, at the top of...

Display all currently defined variables

Is this possible without a debugger? I mean, we have $_POST, $_GET, $_SESSION, etc. I'm looking for something like $_CURRENT_VARS ...

What are the PHP-specific antipatterns that you know of?

PHP as a Blunt Instrument I hear PHP getting bashed around a lot lately. In quite a few projects, I have seen insane php code bases - so bad you really wonder if the person was on hallucinogenic drugs when they wrote the code. Sometimes, I wonder what the code would have been like if the initial developers had a bit more guidance as to ...

php array_merge without erasing values?

Problem: by default, PHP array_merge works like this ... it will overwrite a non-blank value with a blank value. $foobar = Array('firstname'=>'peter','age'=>'32','nation'=>''); $feebar = Array('firstname' => '','lastname' => 'griffin', age =>'33','nation'=>'usa'); print_r(array_merge($foobar,$feebar)); /* Array ( [first...

Use one bind_param() with variable number of input vars

I try to use variable binding like this: $stmt = $mysqli->prepare("UPDATE mytable SET myvar1=?, myvar2=... WHERE id = ?")) { $stmt->bind_param("ss...", $_POST['myvar1'], $_POST['myvar2']...); but some of the $_POST['...'] might be empty so I don't want to update them in the DB. It's not practical to take into account all the differen...

CodeIgniter/PHP/MySQL: Retrieving data with JOIN...

Hi, I'm new to PHP/MySQL and super-new to CodeIgniter.. I have information in many MySQL tables. I want to retrieve it with JOIN where the tables primary keys are equal to $variable... How can I do it and get all the fields without the primary key field??? What I'm doing now is this (only two tables joined here): function getAll($id) {...

building timezone feature in PHP web application

This is almost similar question to this one: - http://stackoverflow.com/questions/346770/dealing-with-timezones-in-php I read that thread, and have some more issues, and not sure of how to elegantly build timezone support in PHP/MySQL application. I am writing an application in PHP, where users can select their timezone. Here, all ti...

PHP: Textile giving me single quotes instead of apostrophes

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and all of my apostrophes (ex. It's hot in here) are being translated to ASCII ‘ (which is a single quote, which slopes the wrong way). What it should be is ASCII ’. I've also tried usi...

Shorten Zend Framework Route Definitions

Hi! How can I shorten the definition of my custom routes in Zend Framework? I currently have this as definition: $route = new Zend_Controller_Router_Route( ":module/:id", array( "controller" => "index", "action" => "index" ), array("id" => "\d+") ); self::$frontController->getRouter()->addRoute('shortcutOne', $route); $route =...