php

How to Automatically Start a Download in PHP?

What code do you need to add in PHP to automatically have the browser download a file to the local machine when a link is visited? I am specifically thinking of functionality similar to that of download sites that prompt the user to save a file to disk once you click on the name of the software? ...

Smarty integration into the Code Igniter framework.

A little background: I've been looking at a few php framework recently and it came down to 2 framework. The zend framework or Code Igniter. I prefer CI because if it's simple design. It's very barebone and just kept it simple. But the thing I didn't like is the weak template system. The template system is important for me because I wil...

How do I execute PHP that is stored in a MySQL database?

I'm trying to write a page that calls PHP that's stored in a MySQL database. The page that is stored in the MySQL database contains PHP (and HTML) code which I want to run on page load. How could I go about doing this? ...

How to fetch a Book Title from an ISBN number?

I am planning on creating a small website for my personal book collection. To automate the process a little bit, I would like to create the following functionality: The website will ask me for the ISBN number of the book and will then automatically fetch the title and add it to my database. Although I am mainly interested in doing this...

PHP Include function outputting unknown char

When using the php include function the include is succesfully executed, but it is also outputting a char before the output of the include is outputted, the char is of hex value 3F and I have no idea where it is coming from, although it seems to happen with every include. At first I thbought it was file encoding, but this doesn't seem ...

Setting include path in PHP intermittently fails. Why?

I have tried both ini_set('include_path', '.:/usr/share/php5:/usr/share/php5/PEAR:lib:app/classes'); in the code itself and also php_value include_path ".:/usr/share/php5:/usr/share/php5/PEAR:lib:app/classes" in the .htaccess file. Both methods actually do work but only intermittently. That is, they will work fine for about 37 pa...

PHP Library Best Practices?

I'm working on a project that I'd eventually like to package as a reusable PHP library. Can anyone suggest some best practices for doing so? Directory structure? File naming conventions? Anything else I might not be thinking of? Or should I just put everything in an appropriately named .php file or two and call it good? Thanks. ...

PHP, Arrays, and References

Why does the following code not work as I was expecting? <?php $data = array( array('Area1', null, null), array(null, 'Section1', null), array(null, null, 'Location1'), array('Area2', null, null), array(null, 'Section2', null), array(null, null, 'Location2') ); $root = array(); foreach ($data as $row) { if ($...

Variable Types

I know that I can do something like $int = (int)99; //(int) has a maximum or 99 To set the variable $int to an integer and give it a value of 99, Is there a way to set the type to something like LongBlob in MySQL for LARGE Integers in PHP? ...

Is there a better way of writing a git pre-commit hook to check any php file in a commit for parse errors ?

What I have so far is #!/bin/sh php_syntax_check() { retval=0 for i in $(git-diff-index --name-only --cached HEAD -- | grep -e '\.php$'); do if [ -f $i ]; then output=$(php -l $i) retval=$? if [ $retval -gt 0 ]; then echo "===========================================================================...

In PHP, is there an easy way to get the first and last date of a month?

I need to get the first and last day of a month in the format YYYY-MM-DD given only the month and year. Is there a good, easy way to do this? ...

Given that I have a hash of id(key) and countries(values) sorted alphabetically, what is the best way to bubble up an entry to the top of the stack?

This is a php example, but an algorithm for any language would do. What I specifically want to do is bubble up the United States and Canada to the top of the list. Here is an example of the array shortened for brevity. array( 0 => '-- SELECT --', 1 => 'Afghanistan', 2 => 'Albania', 3 => 'Algeria', 4 => 'American Samoa', 5 =...

Stream data (such as music) using PHP (or another language)

For years, I've been investigating how to create music streams from my computer. I've seen programs, but anything useful I've seen is windows only (I use a Mac). Eventually, I got interested in how streams work. Is there any way I could create my own stream, possibly using socket functions in PHP? Is there a PHP library for this? Th...

Automate Deployment for Web Applications?

My team is currently trying to automate the deployment of our .Net and PHP web applications. We want to streamline deployments, and to avoid the hassle and many of the headaches caused by doing it manually. We require a solution that will enable us to: Compile the application Version the application with the SVN version number Backu...

php execute a background process

I need to execute a directory copy upon a user action, but the directories are quite large, so I would like to be able to perform such an action without the user being aware of the time it takes for the copy to complete. Any suggestions would be much appreciated. ...

Redirect from domain name to a dotted quad hosted box

I have a php server that is running my domain name. For testing purposes I am running an asp.net on a dotted quad IP. I am hoping to link them together via either php or some kind of dns/htaccess voodoo. So if I go to www.mydomain.com/test it redirects (but keeps the url of (www.mydomain.com/test) in the main bar or awesome bar or wh...

Test Driven Development in PHP

I am a web-developer working in PHP. I have some limited experience with using Test Driven Development in C# desktop applications. In that case we used nUnit for the unit testing framework. I would like to start using TDD in new projects but I'm really not sure where to begin. What recommendations do you have for a PHP-based unit test...

Can you access a model from inside another model in CodeIgniter?

I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside another model. Is there a way to access a model from inside another model? or Is there a better way to handle authentication inside Cod...

How to Dynamically Generate String Validation?

Does anyone know of a library (preferably php) or algorithm for auto-generating regex's from some common descriptions? For example, have a form with the possible options of: Length (=x, between x & y, etc) Starts with Ends with Character(s) x(yz) at index i Specify one or more alternative behavior based on the above And so on.. The ...

htmlentities vs htmlspecialchars

What are the differences between htmlspecialchars and htmlentities. When should I use one or the other? ...