php

Is it overkill to put MySQL select statements in a class and CRUD statements in a child class?

I have 2 classes for accessing the database: MovieDAO - access database using "select" statements only; the purpose is for retrieving data for displaying in the web browser. and MovieExtendedDAO (extends MovieDAO) - which is more complete and allows for creating/updating/deleting a movie in addition to the inherited functionality. Th...

Is using a front controller and headers the best way to mimic a response in PHP?

I've been researching PHP frameworks as of late for some personal projects, and it looks like most of them use a front controller to mimic a response. The controller gets the params from the request, and re-routes by sending the appropriate headers depending on the logic. This is the "response". Is this the best way to do this in PHP, or...

Possible circular dependency issue with PHP application

I'm experiencing what I believe is a circular dependency issue with my PHP application. Please let me know if this is incorrect. Here is the situation: Two classes, LogManager and DBSession. DBSession is used to interact with the database, and LogManager is used to log to files. Both are widely used in my application. When you create a...

Swap every pair of characters in string

I'd like to get all the permutations of swapped characters pairs of a string. For example: Base string: abcd Combinations: bacd acbd abdc etc. What's the best way to do this? ...

Can require_once be used with symbolic links?

On a CentOS LAMP box, trying to get require_once to work inside a script in PHP5. If the file to be included is not a in symlinked directory, it works fine, but if the file to be required is in a directory found via a symbolic link, it fails to find it. Is this a limitation of require_once and symbolic links? EDIT - Thanks for the inpu...

Problems with deleting XML elements using PHP DOM

Here's the XML file i'm working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php, page that shows the list of activities with checkboxes, a button to delete the checked activities, and a field to add new activities: <html> <head></head> <body> <?php ...

How can I split a PHP script that takes a long time to run into smaller chunks?

I have a PHP script that initialises an image gallery. It loops through all images, checks if they are thumbnailed and watermarks them. My shared hosting account only lets me have 30 seconds of execution per script, as set in the php.ini settings. I can't change that. What can I do to get round this? Currently I refresh the page after ...

Why do I get "permission denied" in PHP when trying to rename a directory?

I chmod'ed the directory to 777, same with the directory contents. Still, I get a "permission denied" error. Does PHP throw this error if apache is not the group/owner, regardless of the file permissions? Here's the call that's failing: rename('/correct/path/to/dir/1', '/correct/path/to/dir/2'); ...

Custom php template engine: Am i finally on the right track?

Hi everyone, Since I keep showing up late for answering questions tagged php where i actually know the answer i figured i'd try asking a question myself. I've been working on so many complete rewrites of a custom template engine in php for so long and so many times that i thought i'd ask for opinions. In short, this is the most import...

Is a custom module the best way to access an external API in Drupal?

I'm new to extending Drupal, though I've done similar kinds of things for other CMSes. Anyone care to share opinions on the best way to access an external API from within Drupal? I need to show things like search results, listings, and listing summaries. In my reading up on Drupal, I think this implies I need to create both "nodes" and ...

Complex Find in Cake PHP

Hey all I'm hoping someone has enough experience with Cake PHP to make this work. I'm working on something that at the moment could affectionately be called a twitter clone. Essentially I have a set up like this. Users have many friends. This is a many to many relationship to the user table. It is stored in a link tabled called frien...

Using Wordpress LOOP with pages instead of posts?

Is there a way to use THE LOOP in Wordpress to load pages instead of posts? I would like to be able to query a set of child pages, and then use THE LOOP function calls on it - things like *the_permalink()* and *the_title()*. Is there a way to do this? I didn't see anything in *query_posts()* documentation. ...

PHP: Best way to extract text within parenthesis?

What's the best/most efficient way to extract text set between parenthesis? Say I wanted to get the string "text" from the string "ignore everything except this (text)" in the most efficient manner possible. So far, the best I've come up with is this: $fullString = "ignore everything except this (text)"; $start = strpos('(', $fullStrin...

Prepared Statement vs. Stored Procedure

If you are using php5 and mysql5, is there a substantial advantage to using stored procs over prepared statements? ( i read somewhere you may not get substantial performance gains from mysql5 stored proc) ...

Print out post values

I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value. ...

PHP-Based Manual Apps

Are there any well-made web apps for writing tehcnical/API type manuals? I've got some code I want to write some "getting started" guides for and maybe some reference content. PHPDocumentor is all fine and good for documenting my class heirarchy, but I also want to put something together that is a bit more human readable and linear. I s...

Why not use 'protected' or 'private' in PHP?

I've been working with the Joomla framework and I have noticed that they use a convention to designate private or protected methods (they put an underscore "_" in front of the method name), but they do not explicitly declare any methods public, private, or protected. Why is this? Does it have to do with portability? Are the public, pr...

What is the best way to escape Python strings in PHP?

I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg. subject_prefix = 'This String From User Input' msg_footer = """This one too.""" The contents of subject_prefix et al need to be written to take user input; as such, I need to escape the contents of the strin...

wordpress - having comments inline ajax like in stackoverflow

i have a wordpress blog and want to give people the same user experience for adding comments that is in stackoverflow. There are a number of comments ajax plugins out there but i can't find a working one that allows you to inline on the main page, go in and add comments without first drilling down into a seperate single post page. Can ...

<?php system('php file.php'); ?> doesn't work, why?

neither <?php system('/usr/bin/php file.php'); ?> I tried with -q, with !#/usr/bin/php etc... anyone can help? ...