php5

How to handle user input of invalid UTF-8 characters?

I'm looking for general a strategy/advice on how to handle invalid UTF-8 input from users. Even though my webapp uses UTF-8, somehow some users enter invalid characters. This causes errors in PHP's json_encode() and overall seems like a bad idea to have around. W3C I18N FAQ: Multilingual Forms says "If non-UTF-8 data is received, an e...

Auto Generate Field Names from table PHP

Hi There! There is a problem of automatically retrieving field names from a MySQL table. If possible could the name be placed in this format along with the dynamically created text box? : The codes that I have created so far are located below: <?php include "db_connect.php"; $name = mysql_query("SELECT * from users"); $property = m...

PHPUnit: Test an abstract class without concrete methods

Hi all, I've following abstract class and have a question about how to write a unit test for this. Is this in fact needed? As this class doesn't have any concrete methods. <?php abstract class PickupPoint_Abstract { public function __construct($client) {} public function getPickupPoints($countryCode, $postalCode, $city) {} ...

Has anyone compiled a rabbitmq/amqp library for php 5.2.x on windows x64

I'm trying to publish messages to RabbitMQ from a php (5.2.x) script on my windows X64 dev machine. The problem is that I didn't find any dll extension for php. My collegue is actually trying to build it (cf. How do you compile a PHP extension on windows with cygwin/mingw?), but without success :(. Does anyone know where I can find a v...

How to auto call function in php for every other function call

Class test{ function test1() { echo 'inside test1'; } function test2() { echo 'test2'; } function test3() { echo 'test3'; } } $obj = new test; $obj->test2();//prints test2 $obj->test3();//prints test3 Now my question is, How can i call another function before any called function execution? In above case, how can i auto call 'test1'...

PHP Debugging with Breakpoints - case studies, examples..?

I'd really like to get deeper into my php scripts and use things like breakpoints, as I'm doing with JS with firebug. I've recently had no end of "fun and games" with magento and ZF, and I'm certain that some more sophisticated debugging techniques would have saved a lot of time.... ;) However, there doesn't appear to be much in the w...

phpinfo() shows cURL enabled, I'm still unable to use it

I am in the process of making a page fetch script & I was using curl for it. I used the function: get_data($url); but I always get the error: Fatal error: Call to undefined function get_data() in D:\wamp\www\grab\grab.php on line 16 I am using WAMP server and I have enabled curl extentions in all the ini files, I have checked the ex...

php script to log the raw data of POST

Hi, I am sending data using HTTP POST to my server. But in the server, I am not receiving the data. And somehow I don't have any way to check the data (or debug script) on client side. But on client side I am getting HTTP 200, means data is sent. Also I can see the connection and data sending was successful. However log in the server doe...

PHPUnit: Test an an factory class with a dependency

Hi all, I've got following factory class which has a dependency $client. I moved the dependency to the factory class as it first occurred in Service_Service1 class so I could test the service class. But how can I test the factory class? class Factory implements Service { public static function factory($service) { $conf...

PHP ftp_login() not accepting username and password

We're migrating from PHP 4 to 5 (FINALLY!) I need a php script to connect to an external server over SSL-FTP. Long story short, this works on PHP 4, but not 5. <? $user = "USER"; $pass = "PASS"; $conn_id = ftp_ssl_connect("WEBADDRESS.com",21) or die ("could not connect"); $login_result = ftp_login($conn_id,$user,$pass); ?> On 5 it r...

MySQL trigger + notify a long-polling Apache/PHP connection

I know there are Comet server technologies that do this but I want to write something simple and home-grown. When a record is inserted into a MySQL table, I want it to somehow communicate this data to a series of long-polled Apache connections using PHP (or whatever). So multiple people are "listening" through their browser and the sec...

Best solution for "Array chaining"

For my project I wrote a small config class that loads its data from a .ini file. It overwrites the magic __get() method in order to provide simplified access to the (read only) config values. Example config.ini.php: ;<?php exit; ?> [General] auth = 1 user = "halfdan" [Database] host = "127.0.0.1" My config class (singleton pattern...

how to parse a HTML page with PHP5 and DOM?

hi there! i'm working on some piece of code that should get the contents of a very specific html-tag of an html-document given. $html = "<html>..........truncated.........<div>blablabla<br />xy</div>....."; $dom = new DomDocument(); $dom->loadHTML($html); $divs = $dom->getElementsByTagName('div'); echo $divs->item(0)->nodeValue.'<br>...

Accessing private variables from within a closure.

I'm trying to reference a private variable of an object from within a closure. The code below would seem to work, but it complains Fatal error: Cannot access self:: when no class scope is active in test.php on line 12 and Fatal error: Using $this when not in object context in test.php on line 20. Any ideas how to accomplish the same res...

PHP method chaining?

Hi, I am using PHP5, and heard of a new featured in object-oriented approach, called method chaining. Does any one know what it is? I want to know how to implement method chaining using PHP5 with object-oriented approach. Thanks ...

Problem with input fields in Chrome,FF,Opera,Safari, not in IE

I'm using the AutoSuggest jQuery Plugin: http://code.drewwilson.com/entry/autosuggest-jquery-plugin So basically what it does is create a hidden input field containing comma separated values; the IDs of the Names in the AutoSuggest field. Using Firebug, I confirmed that the hidden field was created and the IDs were inserted in the 'valu...

How do I configure Apache to use a new version of PHP?

After downloading, building and installing a new version of PHP5 on a SuSe Linux distribution, I can not get Apache to recognize it. Why isn't mod_php5.so being overwritten? Or do newer versions of PHP use a different so? ...

IIS7 Basic Authentication on PHP Site

I have a PHP5 site running on IIS7 and I just wanted to add basic authentication on a subfolder called admin. I enabled both anonymous authentication and basic authentication and I just want to turn off anonymous authentication on the subfolder in order to force the basic authentication? Any suggestions? I tried adding a web.config in...

Extract something from array

Hello, I have thsi result if I vardump an array. `object(stdClass)#284 (39) { ["nid"]=> string(3) "516" ["type"]=> string(10) "classified" ["language"]=> string(2) "de" ["uid"]=> string(4) "5074" ["status"]=> string(1) "1" ["created"]=> string(10) "1284678918" ["changed"]=> string(10) "1284678918" ["comment"]=> string(1) "0" ["...

Best way to parse this string

In PHP what is the most efficient way to parse this string into an associative array? %STCITY^LASTNAME$FIRSTNAME$MIDDLENAME^ADDRESS1$ADDRESS2^?;UNIQUEID=YYMMDDYYMMDD=? ...