php

preg_match_all question (how to limit scope without a seperate preg_match call)

Hello, I have some data similar to this: aaa1|aaa2|ZZZ|aaa3|aaa4|aaa5|ZZZ|aaa6|aaa7 I want to match all "aaa[0-9]" BETWEEN "ZZZ" (not the ones outside). So I have some PHP code: $string = "aaa1aaa2zzzzaaa3aaa4aaa5zzzzaaa6aaa7"; preg_match_all("/zzzz.*(aaa[0-9]).*zzzz/", $string, $matches, PREG_SET_ORDER); print_r($m...

Is it important to explicitly declare properties in PHP?

I have followed a tutorial to create a simple blog writing application in PHP and have modified the classes in this tutorial so that they have additional capabilities. Modifying this very bare bones app has given me a better understanding of how PHP works, however I have run across an interesting situation. One of the classes in my pr...

PHP: replace invalid characters in utf-8 string in

How replace (use regex in PHP5) invalid characters in utf-8 string on white space characters? ...

retrive data using foreach() from table in php code

Please help in php code $data = mysql_query("SELECT * FROM a2h_member_type") or die(mysql_error()); foreach($data as $row){ foreach($row as $key=>$value){ echo $key; echo $value; } ...

Did I understand right how to build robust php backends with Zend Framework ?

Most of you should know that 'famous' article about "Writing Robust PHP Backends with Zend Framework" After an insteresting reading, i decided to give it a try, since i couldn't be able to find the gold solution to handle my datas. Then, i tried to write kind of a skeleton, to have a concrete example. But some points looks weird for m...

php Object to String

I'm trying to teach myself php... so please be kind and bear with me. I'm trying to follow this tutorial on how to cache files... the page I want to cache is HTML only, so I've modified the php to just deal with data. I know the caching part is working, it's when I try to modify the results that I get a "Catchable fatal error: Object of...

Design Pattern to Handle Grouping Similar Entities Together

Over the past few years I've been on projects where we've run into a similar problem in our object hierarchy that always seems to cause problems. I was curious if anyone here knew of a classical OOP (Java, C#, PHP5, etc) design pattern that could gracefully handle this situation. Say we have an existing system. This system has, among ...

What is the best way to store and search through class objects (in PHP)?

I've around 80 instances of this class called Items and would like to efficiently search the objects by their ID or NAME. <?php class Item { public $id; public $name; //methods } ?> I'm using PHP5. ...

How to enable thumbnail selection for external links? (or: reproduce Facebook's "post to profile" functionality)

When posting a link to your facebook profile, users are presented with the option to choose a thumbnail to represent the link, as seen in the following example: http://www.everyday.com.my/photo/2009/4/Add-Sushi-King-into-my-Facebook-profile.jpg (New users aren't allowed to embed images) The thumbnails presented to the user are the diff...

Apache & PHP folder permissions

Hi, Our PHP scripts create dynamic folders and files and we are having a permission issue. The folders were initially create using our ftpuser. EG: Album (created by ftpuser) all subfolders and files in them have to be dynamically created. The apache user is the user when a new folder is created and then it cannot write anything to that...

Map Clustering Algorithm

My current code is pretty quick, but I need to make it even faster so we can accommodate even more markers. Any suggestions? Notes: The code runs fastest when the SQL statement is ordered by marker name - which itself does a very partial job of clustering the markers (the names of markers in the same location are often, but not alway...

Trigger error from within exception handler

Given that I have a custom PHP error handler already, does it make sense to define an exception handler as an "forwarder" like this: function exception_handler(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } set_exception_handler('exception_handler'); The idea is to utilize the already existing error handler to ha...

How to define an empty object in PHP

with a new array I do this: $aVal = array(); $aVal[key1][var1] = "something"; $aVal[key1][var2] = "something else"; Is there a similar syntax for an object (object)$oVal = ""; $oVal->key1->var1 = "something"; $oVal->key1->var2 = "something else"; ...

UPS freight calculator

I have managed to get a UPS Shipping calculator working in PHP. I now found out that the standard shipping from UPS is capped at 150lbs. For anything over 150lbs, I need to ship via freight. Has anyone ever coded a Freight Calculator with UPS? The calculator I wrote for anything under 150lbs does not require a UPS account. I was hop...

Auto generate email account during Drupal account registration?

I was wondering how to auto generate a user email accounts in Drupal? I do not have a host currently but am trying to get my head around how this would be done. ...

PHP: Can we build a web application to send email from localhost, like ThunderBirds, OutLook.?

Hi All I don't know whether or not it's a good question :( But my intention is to know if it is possible to to build an email client application like Thunderbird or OutLook . And can we able to configure/create a Web Application in PHP? Please let me know your thoughts! Thanks in advance!!! ...

how to speed up Mysql and PHP?

Hello I am developing a script in my localhst using PHP and mysql and I am dealing with large data (about 2 millions of records for scintific research) some queries I need to call once in a life (to analyse the data and prepare some data); however it takes very long time for example: now my script is analysing some data for more than 4...

php $_SERVER['argv'][0] error in osCommerce

Hi, I am running an osCommerce app on GoDaddy.(I'm not a php expert though) I recently found that some admin pages give errors. I narrowed the problem down to the following line. $pIDlist_array=split("&", $_SERVER["argv"][0]); $_SERVER["argv"][0] returns always NULL. I think it's because register_argc_argv is off in global php confi...

Lamp / Cakephp: Streaming an image : Binary 0x00 replaced by 0x20

I'm trying to create a script that pulls an image out of the database and displays it to the user, called by <img src="viewImage/someImageName"> But the problem I'm having is when the image is displayed all of the Nulls (0x00) are replaced by 0x20 and I have no idea why. The data in the database shows it being nulls but somewhere along ...

How to generate json using php?

Hi, I've never used JSON before and I'm trying to utilize the following javascript: http://jqueryselectcombo.googlecode.com/files/jquery.selectCombo1.2.6.js It needs a JSON output in the following format: [{oV: 'myfirstvalue', oT: 'myfirsttext'}, {oV: 'mysecondvalue', oT: 'mysecondtext'}] Could you guide me to an example on how to gen...