php

MySQL database config in a seperate class

Is it possible to keep all my database related configuration (hostnames, usernames, passwords, and databases) as well as the function to connect to and select the correct database in a seperate class? I tried something like this: class Database { var $config = array( 'username' => 'someuser', 'password' => 'somepass...

Is this bad Object Oriented PHP?

I've created a Display object that contains the header, sidebar and footer: class Display { protected $framework; public $mysql; public function __construct() { $this->mysql = new MySQL(); $this->framework .= $this->header(); $this->framework .= $this->body(); $this->framework .= $this->sideba...

Drupal Form-API: #field_prefix doesn't work on textfield

I'm trying to implement #field_prefix on a text field so I can add some extra UI to my form. I have a module where I'm doing other overrides like this, with a function that basically looks like this: function modulename_form_alter(&$form, $form_state, $form_id){ if ($form_id == "contenttype_node_form"){ $form['field_content...

PHP - editing text file above root

Hi , I'm using PHP & i wanted to put a text file above(outside) the website root so users can't access it. But i wanted to know how can i read it from my code, i want to open, write/edit some data then save it. Please give me an example. Thanks , ...

PHP DOM Dumb Question- Add Nested Children

Hi All, I am moving some code from SimpleXML to php's DOM and don't quite get the objects yet. In SimpleXML, for example, I can create nested elements very easily like so: $Settings = new SimpleXMLElement("<root></root>"); $Settings->addChild('el1'); $Settings->el1->addChild('el2'); $Settings->el1->el2->addChild('el3'); $Settings->el1...

PHP & MySQL on Mac OS X: Access denied for GUI user

Hey! I have just installed and configured Apache, MySQL, PHP and phpMyAdmin on my Macbook in order to have a local development environment. But after I moved one of my projects over to the local server I get a weird MySQL error from one of my calls to mysql_query(): Access denied for user '_securityagent'@'localhost' (using pass...

php mysql connection confusion

Hi guys, had a bit of confusion going around in work earlier. Thought id run it by yous to see if anyone knows wats going on. Were working on an internal administration system for our client, and its rite about to launch. Its comprised of TWO MySQL databases on the server [db_1 and db_2] and a PHP front end. [Both databases contain seve...

Can you store an Array in Memcache?

Can you store an Array in Memcache? I would like to store; A user ID number A user's photo URL A users name Together as an array, someone told me you could and then someone told me you couldn't Which is it? ...

Shorten array in PHP: 20 values => X values

Hello! In PHP I have an array containing 20 elements or more. The keys have been assigned automatically. The values are random numbers from 1 to 50. <?php $randomList = array(); for ($i = 0; $i < 20; $i++) { $randomList[] = mt_rand(1, 50); } ?> Now I want to plot this array into a line chart. Unfortunately, I can only use 5 points ...

How do I use that "<<<HTML" thing in PHP?

I know I shouldn't be outputting things directly in PHP, but using a template instead, but whatever. I remember perl being able to do this, and as I reached for my perl book, I realized: I already packed it, as I'm moving. It's incredibly difficult to search for "<<<", as well. So, I know I can go, echo <<<SOMESTUFF blah blah blah ...

How can I get an HTML page as a string via PHP?

I am fetching some info via PHP from a webpage using simple_php_dom and curl. The problem is that the page is not built correctly so the DOM object contains erroneous info. How can I get the HTML file as a string in a PHP var so that I can run a regular expression through it? Curl doesn't work as it is ignoring the bad part. simple_htm...

is_dir check is not working

I'm having some problems using / understanding is_dir. (Yes, I have read the PHP doc). I have a baseDIR as following: $baseDIR = 'I:\Development\wamp\www\mySite\wp-content\uploads\' The following code is TRUE and therefore outputs the text: if (is_dir($gallery->baseDIR)) echo 'DIR exists'; Now I need to check if there is a dire...

Dynamically generate classes at runtime in php?

Here's what I want to do: $clsName = substr(md5(rand()),0,10); //generate a random name $cls = new $clsName(); //create a new instance function __autoload($class_name) { //define that instance dynamically } Obviously this isn't what I'm actually doing, but basically I have unknown names for a class and based on the name, I want to ...

email parsing system

i am building a system for automatically parsing incoming emails and populating a database from them initially there will only be 10-20 expected formats coming in, but long term there is the possibility of thousands of different formats the way i see it i need to identify format of email (eg regex on subject line) parse the email wi...

How do I easily determine the age from an birthday? (php)

Possible Duplicate: Calculate years from date Hi, I have a table with a field representing the birthday. How do I find the age of the person from that date? This is what I have. $qPersoonsgegevens = "SELECT * FROM alg_persoonsgegevens WHERE alg_persoonsgegevens_leerling_ID = $leerling_id"; $rPersoonsgegevens = mysql_query(...

PHP error log and newline chars

What's the PHP config setting which allows or prevents newlines in debug output from being escaped? On two different installs (a dev laptop running MAMP/OSX, and a dev server running debian) I see different results in the error logs when debugging. error_log(print_r(array(1,2,4),1)); On Debian this appears in /var/log/apache2/error.l...

Why this web page is suddenly being displayed wrongly in IE7

Hello, I'm having a problem that's intriguing me. I decided make a few changes (in a link and inserting metatags) in the index.php file from my company's site: http://www.expresssignproducts.com and after I uploaded the header pictures were all misaligned in IE7 (others were fine). So I uploaded the previous version of the file... same b...

Is it good programming practice to have a return statement in all functions?

I have a basic programming question. I would like to know if every non-void function should have an "return" statement in PHP script. Take the following two example functions. Which one would be the better way to program? They both do the same thing (to my understanding) but which is the "better practice" and why? function displayAp...

Is there a way to have PHP subclasses inherit properties (both static and instance)?

If I declare a base class as follows: abstract class Parent { protected static $message = "UNTOUCHED"; public static function yeah() { static::$message = "YEAH"; } public static function nope() { static::$message = "NOPE"; } public static function lateStaticDebug() { return(static...

How can I pass the correct variables in a URL in PHP for my paging?

I am working on paging in PHP I need it to work on any folder so root/ root/folder1/ root/folder1/folder2/ would all work It should pass the page number variable for the script to work in the URL but also retain any other variables in the URL that may be present with any amount of variables passed in tthe URL Here is what I have so...