php

[PHP] Multiple Seperate Switch Statements

Hi :) I have multiple switch statements in on one of the pages in order to pass different vsriables to the URL, as well as different case. I need these different switch statements because I need the different variables. However, when I put a "default" in one of the switch statements, that default applies to every other switch statement...

Is there a PHP feed reader for both RSS and ATOM?

Hello, I need a PHP library/script that can retreive data from feeds, no matter if they are RSS or ATOM, because I want users to insert random feeds which will then be stored in a database. It would also be great if it could check whether a given URL is a feed or not. If anything exists that could help me out, could anyone tell me? Tha...

AJAX Progress: Reading output from the Shell

Hello all, Objective: Make a progress bar where users can check how much of a file has been downloaded by my server. Scenario:I have a PHP script that executes a python script via popen. I have done this like so: $handle = popen('python last', 'r'); $read = fread($handle, 4096); pclose($handle); This python script outputs to the s...

php function for collating external variables into a single object regardless of GET or POST

Question: I recall reviewing someone else's PHP code once and he had a function or class method that rolled all GET and POST variables into a single plain old object that could then be passed around. If the same name-value pair appeared in both GET and POST, POST would win. Is there a well-coded PHP add-on out there of any sort that doe...

reducing duplication in static HTML pages

Hi, I have a website which consists of a bunch of static HTML pages. Obviously there's a lot of duplication among these (header, menu, etc). The hosting company I plan to use supports PHP, which I know nothing about. Presumably PHP provides some sort of #include mechanism, but what changes to I need to make to my HTML pages to use it? ...

How to choose more than one option from a select box

Hi all, i want to know how can we select more than one option from a select box like given below: Colors Black White Tan Navy Royal Blue Red Yellow Hunter(Dark Green) Kelly(Green) Burgundy Thanks ...

What things are best not done in a constructor?

I started off by drafting a question: "What is the best way to perform unit testing on a constructor (e.g., __construct() in PHP5)", but when reading through the related questions, I saw several comments that seemed to suggest that setting member variables or performing any complicated operations in the constructor are no-nos. The const...

Phpmyadmin login script

I trying to code a login script for phpmyadmin <?php $user = "Domain"; $passwords = file("passwords.txt"); foreach ( $passwords as $pass){ $source = file_get_contents("http://dbadmin.one.com/index.php?lang=en&amp;server=1&amp;pma_username=$user&amp;pma_password=$pass"); if(preg_match("/Database/", $source)): echo "Login Worked wit...

Python's equivalent of $this->$varName

In PHP I can do the following: $myVar = 'name'; print $myClass->$myVar; // Identical to $myClass->name I wish to do this in Python but can't find out how ...

Dynamic Include Safety

Is there any way to safely include pages without putting them all in an array? if (preg_match('/^[a-z0-9]+/', $_GET['page'])) { $page = $_GET['page'].".php"; $tpl = $_GET['page'].".html"; if (file_exists($page)) include($page); if (file_exists($tpl)) include($tpl); } What should I add to make this pretty safe? I'm doing it this wa...

Future of Fusebox framework

Good old Fusebox was my first framework and I still really like it. Started with PHP version, currently using latest CFML version. But time goes by and I'm wondering: maybe I should switch to another framework? Well, I don't want to start holy war here. I just want to know the pros and cons of continuing using FB. Say, I think that n...

RegEx: matching and replacing ABC in "AB ABC D"

I need advice on this snippet $text = preg_replace('|(A.*)?A(.*)C|', '$1foo$2bar', $text); This will match ABC in "AB ABC D", and replace it with "AB fooBbar D"; as you can see this matches the "AB " part at the beginning as well, which I have to repeat in the replacement string with $1, in order not to lose it. Is this the best way ...

Resize iframe height according to content height in it

Hi all, I am opening my blog page in my website, problem is i can give width to iframe but height should be dynamic so that there is no scroll bar in iframe and it looks like a single page... i have tried various javascripts to calculate height of content but all of them gives access denied permission and of no use. my question is c...

Simple PHP Framework

I'm looking for a simple PHP framework for a beginner :) Any recommendations? Not Codeigniter. That's too much for me. Thanks in advance. ...

Hyperlinks stop working in firefox after redirect?

On a project I'm working on, I am using HTTP headers to redirect the user to the frontpage after a successful login; header("Location: http://example.com/index.php?"); exit(0); EDIT: Added questionmark to url to show the problem This works fine in all browsers tested - however, in Firefox 3.0.6, both on windows, mac and debian, it fa...

What is the best way to access data in a normalized database schema?

I've got a problem that keeps coming up with normalized databases and was looking for the best solution. Suppose I've got an album information database. I want to setup the schema in a normalized fashion, so I setup two tables - albums, which has one listing for each album, and songs, which lists all songs contained by albums. albums ...

When should I use "final"?

Is there any particular reason I should declare a class or a method final in day-to-day programming (web or otherwise)? Please provide a real-world example where it should be used. BTW, I'm asking because I'm trying to pick an 'obscure' keyword and master it. ...

Output buffer

I am writing a php script and somewhere before my header() function i have printed text to the browser hereby causing my header() function give me a well known error: Warning: Cannot modify header information - headers already sent. Now my question is, I have the intentions of using ob_start() and ob_flush() before and after the he...

Do you only run htmlspecialchars() on output or is there other functionality you also do?

When outputting user input, do you only use htmlspecialchars() or are there are functions/actions/methods you also run? I'm looking for something that will also deal with XSS. I'm wondering if I should write a function that escapes user input on output or just use htmlspecialchars(). I'm looking for the generic cases, not the specific c...

Question about Regular Expression Books

Hi Guys, I want to purchase a regular expressions book centered around PHP. I found this one that looks ok: Friedl - Mastering Regular Expressions but it looks like general information about regular expressions and not PHP. My question is: Does the syntax for regular expressions translate exactly from one language to another, ie-> PHP...