php

How do I centralize code from my init functions in all controllers?

public function init(){ $this->view->user = Zend_Auth::getInstance()->getIdentity(); $this->view->siteName = Zend_Registry::get('config')->site->name; $this->view->menu = $this->_helper->generateMenu(Zend_Auth::getInstance()->getIdentity()); $this->view->slogan = Zend_Registry::get('config')->site->slogan; } Thi...

Transform Array

How do I get this array: Array ( [0] => Array ( [max] => 5 [year] => 2007 ) [1] => Array ( [max] => 6.05 [year] => 2008 ) [2] => Array ( [max] => 7 [year] => 2009 ) ) Into this format: [year] => [max]...

Array Merge/Replace

I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] => 0 [2008] => 0 [2009] => 0 ) Array ( [2007] => 5 [2008] => 6.05 [2009] => 7 ) I want to merge these two arrays such that if a value exists in the 2nd array, it overwrites the first array's value. So the resulting array would be: Array ( ...

Fastest serialize data format form PHP reading

I have a PHP frontend and a C++ backend, and I need to be able to send groups of names to the frontend. What serialized format would be the most efficient/fastest for the PHP to read? Example data group1: name1 3923 name2 9879 name3 8944 group2: name5 9823 group3: name9 9822 name1 4894 What would be the fastest for PHP ...

Is this the right place to call the RSS building function?

Is this the right place to call the function that builds the RSS? its for a reddit type of site. function save() { /* Here we do either a create or update operation depending on the value of the id field. Zero means create, non-zero update */ if(!get_magic_quot...

php, whats is the different between strtolower and mb_strtolower?

php, whats is the different between strtolower and mb_strtolower? If i want to convert submitted email address, to be converted to lower-case, which one should i use? Is there any email like this : [email protected] If there are such email, should i still convert the submitted email address to lower case? ...

Should I leave php for Python or Ruby?

First i started with wordpress, than moved to Drupal and realized that any CMS would not fit my needs since i want a really big flexbility in building my aplications (plus i hate to see worthless code, that i will not use but stays there). I give up on already made CMS and started learning php from the begining. But in nearly no time I...

Is there a way to check if the email is EXISTED using php?

I am getting more and more spam emails recently. I already validate my email using regular expression, all the emails must be something like this: [email protected] But the problem i have now is, there are alot spammers, type [email protected], [email protected], these emails are not existed, because i tried to send email to them. H...

correct use of 'construct' when designing classes

I am new to object oriented programming and writing some of my first classes for a PHP application. In some of the simpler classes, I declare a function __construct(), and inside of that function, call certain class methods. In some cases, I find myself instantiating the class in my app, and not needing to do anything with the resultant...

Using javascript to loop dynamically created controls with php

Ok, this situation is a little weird but anyway. This PHP code generates several radiobuttons: for($i = 0; $i<count($questionList); $i++) { echo $questionList[$i]->__get(QuestionId).'-'.$questionList[$i]->__get(QuestionText).'<br />'; $answerList = $questionList[$i]->GetAnswers(); for($j = 0; $j<count($answerLis...

How to route a multiple language URL with a MVC framework in PHP?

Hi, I would do something similar to this in PHP: http://mysite.com/en/museum/gallery/garden http://mysite.com/es/museo/galeria/jardin It's possible? How can I route the controllers / views using multiple languages? I was wondering if it could be possible with gettext, translating the url automatically, depending on the selected lang...

Should I use \r or \n for explode()ing the contents of a file in PHP?

I'm creating a function which can accept a string which is either retrieved through file_get_contents() on a local text file, or something fetched from a url such as http://site.com/338383.txt. The file will be a tab seperated file, with each item in the file being on its own line. Is it better to use \n or \r to explode() the string an...

Unite two MySQL queries with a UNION or programmatically

I've got two MySQL queries that both insert data into a table. Both have the following format: CREATE TABLE IF NOT EXISTS `data` ( `id` BIGINT NOT NULL AUTO_INCREMENT UNIQUE, PRIMARY KEY (`id`) ) SELECT `field1`, `field2` WHERE `active` = 1 The only differences between the two queries are how field1 and field2 are determined, and some...

Is a versioning system or code repository necessary for a single developer?

Why do I need to use a versioning system or repository? I code from scratch by myself and make web code changes along with database changes on reasonably large projects. ...

International Fonts Display Issue with UTF-8

Hi We have developed a PHP-MySQL application in two languages - English and Gujarati. The Gujarati language contains symbols that need unicode UTF-8 encoding for proper display. The application runs perfectly on my windows based localhost and on my Linux based testing server on the web. But when I transfer the application to the clie...

Best PHP download to keep all my options open?

In the past, I used WAMPserver on windows to parse PHP for me. This is a pre-configured package, focussed on working with MySQL. When I tried to run PostgreSQL, I got error messages that said that my version of PHP wasn't compiled to work with PostgreSQL. So, I've recently uninstalled WAMP and every associated with it. I've downloaded ...

Making shebang dynamic in PHP CLI scripts

I wonder if is there any way to make shebang value on the top of my PHP CLI files dynamic (being set as a constant on a config file)? Is there any one who had an experience about this before? ...

str_replace

Hi folks! Current code only replace the spaces to dash (-) $url = str_replace(' ','-',$url); I want only letters, numbers and dash (-) allowed on the URL. Let me know the tricks. ...

MySQL/PHP Query

I have 3 groups of fields (each group consists of 2 fields) that I have to check against some condition. I don't check each field, but some combination, for example: group priceEurBus, priceLocalBus group priceEurAvio, priceLocalAvio group priceEurSelf, priceLocalSelf My example (formatted for legibility) how can this be improved? ...

strange boolean expression solving in php

$foo = 0; if($foo == 'on') $foo = 1; echo $foo; It should be expected the above code outputs "0". However it doesn't, somehow $foo == 'on' results in TRUE, although this obviously is wrong. Replacing the expression with $foo === 'on' gives the right answer, so any suspicions this might be some typing issue seem to be confirmed. Neve...