php

Whats the cleanest way to convert a 5-7 digit number into xxx/xxx/xxx format in php?

I have sets of 5, 6 and 7 digit numbers. I need them to be displayed in the 000/000/000 format. So for example: 12345 would be displayed as 000/012/345 and 9876543 would be displayed as 009/876/543 I know how to do this in a messy way, involving a series of if/else statements, and strlen functions, but there has to be a cleaner wa...

Inserting the current timestamp in to a sql server 2005 database using php

I have absolutely no idea how to do this and my current experiments just end up with the same old errors. It should be simple but i cannot get it to work. I'm not even sure which datatype to use in the db. Any help would be much appreciated ...

Writing to multiple tables in PHP.

$sql = "INSERT INTO images (path, useremail, approved, flagged,caption,date) VALUES ('$target','$email',0,0, '$caption','$b')"; $sql1 = "INSERT INTO users (name, email, phone) VALUES ('$peoplename','$email','$phone')" $conn->execute($sql, $sql1); Above is the code Ι am using to try and write to 2 tables. Before Ι introduced connection ...

When posting info from a form, is it better to use $_REQUEST or $_POST?

I have a form a user can enter their name, then it will add it to $message to be sent in an email. Is it better to use $_POST or $_REQUEST? Here is a snippet of using $_REQUEST $message.= "Name: ".$_REQUEST["fname"]." ".$_REQUEST["mname"]." ".$_REQUEST["lname"]."\n"; ...

PHP: Removing an attribute from a DOMNode object

I've got a DOMNode object that has some attributes. $Node->attributes is a DOMNamedNodeMap, which has no methods for removing one of the entries in the map. The DOMNode class also has no methods for removing attributes from an element. I've looked through a number of the other related classes and none of them seem to provide a mechani...

Transfer variables between PHP pages

I want to get user input in one page, store that in a php variable and use it in another php page. I have tried using 'sessions' but it doesn't seem to be working. Is there another safe alternative? This information is likely to be usernames and passwords. ...

In PHP, how do you change the key of an array element?

I have an associative array in the form key => value where key is a numerical value, however it is not a sequential numerical value. The key is actually an ID number and the value is a count. This is fine for most instances, however I want a function that gets the human-readable name of the array and uses that for the key, without changi...

PHP w/ Zend Debugger on OS X 10.5

I have OS X 10.5 set up with the precompiled versions of PHP 5 and Apache 2. I'm trying to set up the Zend Debugger, but with no luck. Here's what I did: I downloaded ZendDebugger-5.2.14-darwin8.6-uni.tar I created the directory /Developer/Extras/PHP and set the permissions to: Permissions: drwxrwxr-x Owner: root:admin I copied Zen...

How do I stop users circumventing payment?

Hi I have a site that uses paypal to collect payments for electronically displayed data. Variables can't be passed with the URL through paypal (or I can't get them to work) so I have used cookies to pass the item number. However, a crafty user could, after the cookie writing part, enter the paypal redirect URL directly into the address ...

Which is better for encoding HTML for RSS?

I recently introduced HTML into some RSS feeds that I publish (which up to now only had plain text, no markup), and I was wondering which method is better: use character encoding (such as htmlspecialchars) or just encapsulate everything in CDATA? It seems to me that CDATA might be easier, but I'm unclear as to whether there might be any...

Recommendations for sandboxing inside PHP5 or alternatives?

I've been slowly working on a personnel project to run a webmud like game using extjs as my frontend. One of the design choices I made was to allow user-generated evaluated code for game logic. So when the player enters a new "room" a number of state scripts would be called along the lines of "has player been here before, should they b...

PHP Inclued for Windows?

Is there a .dll version of the inclued extension for PHP? The manual's link for Inclued on PECL4WIN doesn't help. I don't have a compiler to build my own DLL. NOTE: The spelling "inclued" is correct! Edit: I don't have a compiler, but do know someone with one... that's really a last resort though. ...

Passing database connection by reference in PHP

The question is if a database connection should be passed in by reference or by value? For me I'm specifically questioning a PHP to MySQL connection, but I think it applies to all databases. I have heard that in PHP when you pass a variable to a function or object, that it is copied in memory and therefore uses twice as much memory imm...

How to create a custom filter for the Drupal View's Module?

I have the Profile, CCK, and Views2 modules installed on a Drupal 6 site. I added a string field to the user profile. I can filter easily on preset values, thru the Views GUI builder, really nicely. However, I'd like the filter criteria to be dynamically set based on other environment variables (namely the $_SERVER['SERVER_NAME']). I...

Processing large (over 1 Gig) files in PHP using stream_filter_*

$fp_src=fopen('file','r'); $filter = stream_filter_prepend($fp_src, 'convert.iconv.ISO-8859-1/UTF-8'); while(fread($fp_src,4096)){ ++$count; if($count%1000==0) print ftell($fp_src)."\n"; } When I run this the script ends up consuming ~ 200 MB of RAM after going through just 35MB of the file. Running it without the stream_f...

Can't use certain characters in a regex

if(!eregi("^([0-9a-z_\[\]\*\- ])+$", $subuser)) $form->setError($field, "* Username not alphanumeric"); Can anybody tell me why it is not allowing characters such as - and *? if(!eregi("^([0-9a-z])+$", $subuser)) $form->setError($field, "* Username not alphanumeric"); That is the original piece of code. A friend changed it t...

How to disable PHP session cookie?

I am writing PHP code where I want to pass the session id myself using POST. I don't want a cookie to store the session, as it should get lost when the user gets out of the POST cycle. PHP automatically sets the cookie where available. I learned it is possible to change this behaviour by setting session.use_cookies to 0 in php.ini. Unfo...

What is it about PHP's fgets() that makes it so horrible on large files?

What is it about fgets() implementation that makes it so horrible on large files vs fread? To demonstrate, run this code: <?php $line = str_repeat('HelloWorld', 100000) . "\n"; for($i=0; $i<10000; ++$i) file_put_contents('myfile', $line, FILE_APPEND); //now we have roughly a 1gig file // We'll even let fread go first incase // the...

Edit in Place Update Script Security

I'm using an Edit in Place jquery plugin which needs to post the data to a script that will do the actual database update. The URL to this update script is easily viewable in the html source as well as with Firebug, so I need to add some sort of authentication check before the update is processed. This is of course so the user can't jus...

Can I Register more than one shutdown function in PHP?

using register_shutdown_function I can register code to execute at the end of a PHP script execution "no matter what". Can I have more than one function registered? This question arises since I may not know if someone has already registered one when I'm about to register my own. Thanks. ...