php

Replacement for PEAR: MDB2 on PHP 5.3

I've been using pear packages in php for years. I'm in the process of upgrading/moving a sites that uses the MDB2 pear package and it has not been updated for PHP 5.3.X. In 5.3, MDB2 is returning those new annoying errors. Unknown: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 390 ...

build-in extractColFromArray?

Is there an equivalent build-in function to that one? (even without the test capability) /** * extracts a column from a 2D associative array, with an optional selection over another column * * @param $aArray array to extract from * @param $aColName name of the column to extract, ex. 'O_NAME' * @param $aColTest (optional) n...

Link wrappers for internationalization purposes

Hi, I am currently internationalizing my site using PHP and ran into this problem. Some string have multiple links in them so I would like to put the links in wrappers to make it easier for translators to translate (since I'm using gettext). For example: The <a href="google.com">dog</a>, <a href="bing.com">cat</a>, and <a href="yahoo....

Openid forbidden error

After I was able to get it (open id library) installed properly, I am facing some problems in getting it to work. I am using the open id selector a jquery plugin. The problem is that when I click on any open id provider image I get an error message saying something like this (after the form is posted to try_auth.php with necessary param...

jQuery click event to change php session variable

What would be the best approach to this? Because, as I found (and it made total sense, only after having tried it :p) that you can't set a PHP variable on javascripts conditions. (duurrhh) The only solution I can come up with is to do an AJAX call to a small PHP file that handles the session variables elm.click(function() { $.post(...

SO-like paginator,how much more mathematical flavour can you add to it?

function paginator($totalPages,$currentPage) { if($currentPage > $totalPages) return false; $aheadmin = max(1,$currentPage - ($totalPages - $currentPage > 3 ? 2 : (5 - ($totalPages - $currentPage) -1))); if($aheadmin - 1 > 1) { $str = '1 ... '; $aftermax = min($currentPage + 2,$totalPages); } else ...

simple explanation PHP OOP vs Procedural?

Hi, I would like to learn PHP and want to get an Idea about OOP and Procedural. I read some other blogs and tutorials about OOP vs Procedural but I still can't understand the approach. OOP vs Procedural Which I should learn? Whats the difference in code? what are the effects? How can a PHP framework help in OOP aproach? (I would lik...

Regex to split a string only by the last whitespace character

Hello, hopefully this should be a quick and simple one, using PHP I'm trying to split a string into an array but by only the last instance of whitespace. So far I have... $str="hello this is a space"; $arr=preg_split("/\s+/",$str); print_r($arr); Array ( [0] => hello [1] => this [2] => is [3] => a [4] => space ) ...which split...

How to detect if the browser supports a language?

Hi, I am building a multilingual website. Is it possible to check if a particular language is installed/supported on the user's machine using PHP or Javascript? I want to detect this and display a message to the user if the language is not supported/installed. Thanks, Mark. ...

PHP coding problem to get multiple instances from an array based on quantity variable within.

Hi Guys, I'm not sure if anyone can help me with a problem I have.. I have a parse function that includes the code: foreach ($values as $element) { $nodeName = $element["tag"]; switch ($element['type']) { case 'open': if ($nodeName == "SHOPPINGLIST") { $this->publicationID = $element["attributes"]["PUBLICATIONID"]; } if ($nodeNa...

Using a random sha512 salt with a sha512 password

I've been trying to improve my password hashing class for a CMS I'm currently building as a personal project. I originally used md5 without salt, then switched to md5salt+md5, then to sha1salt+sha1 and now I've moved over to sha512salt+sha512. I was thinking about adding an iteration loop onto the hashing procedure also. My question i...

Another preg_replace question!

Ive got a string that are words bunched together and I need to seperate them, and every word that ends in 'A' should probably be on a new line, item onea second itema third I also need to check if the word ending in 'A' should actually end in 'A' like extra or sultana. item oneasecond itemand an extra item I have an array full of ...

Application scope in php

Hello, I need to share same array object across all requests irrespective of requests coming from same browser/user. Is there any application scope in php where I could store that array object. I am using php 5.x . ...

PHP class def: Individual accessors/mutators or __set() with switch()?

When defining a PHP class, which is preferred/best practice? Are there any key differences I'm overlooking? It seems like it could be more clean, concise, and convenient to write a __set() magic method and put a switch() construct in it with cases for all the private members to which I want to allow access. It wouldn't be called automag...

Can't render output to screen using PHP?

I have the following scenario. I have a PHP website witch contains about 3 webpages with dynamic content. I want to render this to static content to another file. Eg. contact.php -> contact.html My code looks like this ob_start(); $content = require_once 'contact.php'; ob_end_flush(); file_put_contents("contact.html", $content); So...

Launch XDebug in Netbeans on an external request

I'm using Netbeans 6.7 and XDebug to debug a PHP site on my machine, launching the request from within Netbeans (Project->Debug). This works fine, and is very useful. My question is: Is it possible to attach the debugger to any request that comes in, rather just those I launch from within Netbeans? ie, instead of clicking "Debug", pu...

Is there a PHP function that can escape regex patterns before they are applied?

Is there a PHP function that can escape regex patterns before they are applied? I am looking along the lines of the C# Regex.Escape function. ...

Are there other ways for creating a file using PHP?

I need to create a series of files and I'm using the following method $file = "myFile.txt"; $fhandle = fopen($file, 'w') or die("can't open file"); fclose($fhandle); Are there better ways of doing this? ...

POSTing to different action with Zend_Form (and validation)

I'm using Zend Framework, and am curious about how people handle form submission. Right now, I'm using something like this: public function editAction() { $form = my_form(); $this->view->form = $form; if ($this->getRequest()->isPost() { $params = $this->getRequest()->getPost(); if ($form->isValid($params) {...

PHP: how to open a zip

Hello, is there an easy way to open and create a zip with PHP? ...