php

how to get the date of last week's (tuesday or any other day) in php?

I think its possible but i cant come up with the right algorithm for it. What i wanted to do was: If today is monday feb 2 2009, how would i know the date of last week's tuesday? Using that same code 2 days after, i would find the same date of last week's tuesday with the current date being wednesday, feb 4 2009. ...

PHP debugging with remote shell access

I'm playing with a PHP weblog application using a shared hosting service, as a part of my PHP learning process. The service provider has a typical LAMP environment with remote ssh access. Vim has been my best friend in exploring the PHP code. However, I found it sometimes hard to trace stuff in the code in case of error. For example, s...

Calculate num of 2xadult + 2xchild combinations

a ticketing site offers a discount on "family" tickets. a family ticket is 2 adults, 2 children. the sell tickets page allows a user to enter any number of adult and child tickets. How do I work out how to apply the family ticket discount, then charge all remaining tickets at their relevant cost (i.e. adult tickets cost more than chil...

Multiple DB connection class

How do you create multiple DB connections using Singleton pattern? Or maybe there's better approach, to share the same class but multiple connections? ...

How to efficiently manage multiple installations of a web application?

From my experience, one of the bigger problems we come across during our webdevelopment process is keeping different setups updated and secure across different servers. My company has it's own CMS which is currently installed across 100+ servers. At the moment, we use a hack-ish FTP-based approach, combined with upgrade scripts at spec...

How can I get every n rows in MySQL?

I have a table which contains data recorded every minute, so I have a row for each minute. When returning the data for processing, this accuracy is required for the last 6 hours but after that, a lower level of accuracy is sufficient, e.g. every 5 minutes. I can return all the data into an array and then remove all but every 5th element...

how to incorporate subdomains into MVC framework

Over the time i developed my own framework and it's working great - it's light, it's fast and is proven that can handle decent load. Now I'm working on project that can be described as a online shop where every user will have his sub domain where his items will be available for sale. My framework works by splitting request url by / an...

PHP Exchange 2007 Server SMTP, NTLM Authentication Realm

I am trying to connect to a hosted Exchange setup at sherweb.com via. PHP using SMTP w/ NTLM authentication. When connecting I need to enter the NTLM Authentication Realm. I am receiving the following error from the PHP script, "The requested credential workstation is not defined" I am using the SMTP class and SASL class from phpclass...

php and mysql not showing data, not entering foreach loop

Hello, I am having trouble with modifying a php application to have pagination. My error seems to be with my logic, and I am not clear exactly what I am doing incorrectly. I have had before, but am not currently getting errors that mysql_num_rows() not valid result resource and that invalid arguments were supplied to foreach. I think t...

Lightweight auto-completing PHP editor?

I've been using Eclipse + PDT, but it's kind of slow, especially to start. Does anyone know a "smart", lightweight editor for PHP that supports folding, auto-completion and function parameter reminders and runs on Windows? ...

mysqli binding fields in a prepared statement

Hello, I have the following code, for which I get the error: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in file. If this is only a warning, shouldn't the code still work? I want to do a select * and display all the data except one field, w...

Does the memory used by file_get_contents() get released when it is not assigned to a variable?

When I use file_get_contents and pass it as a parameter to another function, without assigning it to a variable, does that memory get released before the script execution finishes? For Example: preg_match($pattern, file_get_contents('http://domain.tld/path/to/file.ext'), $matches); Will the memory used by file_get_contents be release...

Executing linux commands with PHP

I'm trying to execute a linux command through a PHP command-line script, which is no problem using the exec command. The problem is, the command I am executing (mysqldump) outputs an error message if something is wrong (for example user/password is incorrect). I can't seem to be able to capture this error in order to log it. It just pri...

Best way to automatically remove comments from PHP code

Whats the best way to remove comments from a PHP file? I want to do something similar to strip-whitespace() - but it shouldn't remove the line breaks as well. EG: I want this: <?PHP // something if ($whatsit) { do_something(); # we do something here echo '<html>Some embedded HTML</html>'; } /* another long comment */ some_mo...

mailchimp api & array question

I'm having a bear of a time getting the mailchimp api to cough up info. In their example I'm fine (the first is an abridged version of theirs.) How come when the method changes I can't get the array to show the collected information? why is this valid: (it's taken from here http://www.mailchimp.com/api/rtfm/campaignemailstatsaimall.func...

One code, many websites

I need to develop a project that would allow me to instance many copies of a website, but each copy needs to be a separate website. I could upload the same code to many different accounts, but I would prefer to have only one copy of the code. Each website would be an "instance", so to speak. This way I could upload the code once and upda...

How can I compare two arrays and list differences in PHP?

I'm building a form to do the following: Print a table of users and permissions, pulling from MySQL. Each permission a user has is a checked box, and each one they lack is an unchecked box. Allow an administrator to check and uncheck boxes to grant or remove permissions. When the form is submitted, show a confirmation page with ONLY ...

regex or something to find a file in php

I have a name in a database, lets say its "DFectuoso" and some legacy system stored DFectuoso_randomnameofafile.doc. Now I want to find all the filed "DFectuoso" owns and display links to them in a PHP page. What would be the way to start on this? ...

scope in PHP classes

I am creating a database connection object, and I'm not sure what the best way would be... If I create a dbConnection class which establishes the connection (using mysql_connect) can I then call mysql_query from anywhere in the main script? what about from inside OTHER classes? Do i need to pass the object or attribute as parameters? ...

Writing To The Response in Rails? (Like "echo" in PHP)

I know that I can do this in Rails: <%="hello" %> but is there any way to do this <% echo "hello" %> and get it to show up in the response? I have tried response.write which almost worked, but did not... Edit: print or puts do not do it, because I do not want to write to the console. I want to write to the browser/HTTP client. Ed...