php

Combine two arrays on a key?

If I wanted to associate items from one array with another array via identical values, eg. items.group_id -> groups.group_id, is there an array function to do that neatly? =) I have two arrays: $items = array( [0] => array( 'group_id' => 456, 'item_id' => 123, ...

Generating a truly unique order id in PHP?

I'm considering using this: http://phpgoogle.blogspot.com/2007/08/four-ways-to-generate-unique-id-by-php.html My idea is to use a mixture between 2 and 3. But my question is that, although the chances are small, is there still a chance that two orders with the same order # can be generated if I substring the result to be only 5 characte...

PHP architecture, and pass-by-reference vs pass-by-value

Seeking suggestions from PHP architects! I'm not terribly familiar with PHP but have taken over maintenance of a large analytics package written in the language. The architecture is designed to read reported data into large key/value arrays, which are passed through various parsing modules to extract those report parameters known to eac...

Php - optimizing multiple counter increments

On a very heavy traffic LAMP server I'm using a memory table to keep track of several data items as counters. It is implemented like this: $query = "INSERT INTO daily_info_mem SET di_num=1 ,di_type=9, di_date = current_date(), di_sid= $sid_int ,di_name='user_counter' ON DUPLICATE KEY UPDATE di_num=di_num+1"; The index sets unique di_t...

RegEx string "preg_replace"

I need to do a "find and replace" on about 45k lines of a CSV file and then put this into a database. I figured I should be able to do this with PHP and preg_replace but can't seem to figure out the expression... The lines consist of one field and are all in the following format: "./1/024/9780310320241/SPSTANDARD.9780310320241.jpg" or...

PHP: Use variable name to call static function on Singleton Object

I need to call a static function from an object using the Singleton design, but using a variable as the class name. The best way, $class::getInstance();, is only available in PHP 5.3, and the other way I found, call_user_func(array($class, 'getInstance'));, results in the maximum execution time being breached. Does anyone know why this ...

PHP XML-Export as file download

hi there! i have written a script that prints a XML file to the screen but I want it to open a download dialog so that i could save it as a file. how could i do that? thnx! the script: <?php print '<?xml version="1.0" encoding="UTF-8" ?>'; print "\n <data>"; ... print "\n </data>"; ?> ...

Problem in sending excel file as attachment using mail function in php?

Hi, I have used this code from link below to send excel file as attachment. http://www.hotscripts.com/forums/php/22626-php-form-excel-then-send-email-attachment.html Here is the code I have used: <?php ob_start(); ?> <html> <head><title></title> </head> <body> <body> <center> <table> <tr> <td>Name:</td><td>My Name<...

I want to compare the current date of my server with a date stored in a mySQL database

How can I compare the current date of the web server with a date I have stored in the mySQL database and 3 days before that that in the database to send a notification email ? ...

AJAX only access

I have recently started to code heavily AJAX supported scripts in PHP, thing is, the files being accessed by the AJAX calls can be directly used too, how to disable that? ...

Document root problem in Eclipse/PHP/Zend

Environment: WindowsXP, Eclipse Galileo, Zend Community Edition (I have configured Eclipse to use the PHP binary in Zend.) I configured the Apache document root within Zend to point to my Eclipse project folder. So I can use URLs like this: <form action="http://localhost/myscript.php"&gt;... But this doesn't work work: <form action...

How to merge transparent PNG with image using PHP?

Hello, The situation is this: I have a small 50x50 pic. I also have a small 50x50 transparent picture which contains a frame for the 50x50 pic, so I basically want to put the transparent png on top of the image and merge those two which would lead to a done third picture that looks something like this: http://img245.imageshack.us/i/50x5...

PHP Networking Sockets

Would it be possible to copy this C# program in PHP? var chatsrv = new IPEndPoint(IPAddress.Parse(_charUrl), _chatPort); _chatsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _chatsocket.Connect(chatsrv); var ns = new NetworkStream(_chatsocket); _nw = new Binar...

PHP E_NOTICE does not warn about unassigned values

I have E_NOTICE activated in php.ini. It still does not warn me about unassigned values like $foo++; Tried to set the error_reporting as well. Does not work. error_reporting() is set to 6143, which means that E_NOTICE is activated. This code snippet also warns me with a notice: $foo = bar; Any ideas? ...

Add captcha to this web button useing php

I have a page with some php code that i don't fully understand yet and i have a php snippet for using recaptcha that i think i have a pretty decent handle on. I'm not sure how to integrate the two yet. I see in the captcha code where it triggers the event but im not sure how to block the button till the captcha is done. The existing...

Regex problem - missing matches

Hello, Here's a short regex example: preg_match_all('~(\s+|/)(\d{2})?\s*–\s*(\d{2})?$~u', 'i love regex 00– / 03–08', $matches); print_r($matches); The regex only matches '03–08', but my intention was matching '00–' as well. What is the problem? Anyone could explain? ...

PHP Inject in another users session

Hello, Since every user has a unique PHPSESSID, is it possible for two users, say a to inject info into b's SESSION data using standard PHP running on the server. Note, I am not using this for any wrong purposes. Trying to use it for chatting without DB access. Thank you for your time. ...

How to get json_encode() to work with ISO-8859-1 (åäö)

json_encode() wont work for me when I'm using åäö. Why? And how can I get it to work? The php: echo json_encode($arr); The javascript: var theResponse = JSON.parse(xmlHttp.responseText); When I alert() the response, and the response contains å, ä or ö, the response is = NULL Please, help me out... ...

php echo vs open&close tag

Just to clarify: The issues "echo vs print" and "double quotes vs single quotes" are perfectly understood, this is about another thing: Are there any reasons why one would prefer: echo '<table>'; foreach($lotsofrows as $row) { echo '<tr><td>',$row['id'],'</td></tr>'; } echo '<table>'; over: ?><table><?php foreach($l...

php get DNS records

HI Does anyone know how its possible to retrieve the DNS records for a domain. I have been using php and this function: dns_get_record to do this so far but have realised that this command gets cached DNS records and therefore not the up to date information. Does anyone know a way around this in php or some other language? ...