php

Are named entities in HTML still necessary in the age of Unicode aware browsers?

I did a lot of PHP programming in the last years and one thing that keeps annoying me is the weak support for Unicode and multibyte strings (to be sure, natively there is none). For example, "htmlentities" seems to be a much used funtion in the PHP world and I found it to be absolutely annoying when you've put an effort into keeping ever...

How can I merge PHP arrays?

I have two arrays of animals (for example). $array = array( array( 'id' => 1, 'name' => 'Cat', ), array( 'id' => 2, 'name' => 'Mouse', ) ); $array2 = array( array( 'id' => 2, 'age' => 321, ), array( 'id' => 1, 'age' => 123, ) ); How can I merge the two arrays int...

How to prevent session timeout in Symfony 1.0?

I've used the PHP MVC framework Symfony to build an on-demand web app. It has an annoying bug - the session expires after about 15-30 minutes of inactivity. There is a config directive to prevent session expiration but it does not work. Even workarounds such as this one did not help me. I intend not to migrate to Symfony 1.1 (which fix...

Remote Debugging PHP Command Line Scripts with Zend?

I'm using Zend Studio to do remote debugging of my php scripts on a dev server. It works great for web code, but can I make it work with command line scripts? I have several helper apps to make my application run. It would be really useful to fire up the remote debugger through command line instead of a web browser so I can test these o...

Most efficient way to get data from the database to session

What is the quickest way to get a large amount of data (think golf) and the most efficient (think performance) to get a large amount of data from a MySQL database to a session without having to continue doing what I already have: $sql = "SELECT * FROM users WHERE username='" . mysql_escape_string($_POST['username']) . "' AND password='"...

Iterating over a complex Associative Array in PHP

Is there an easy way to iterate over an associative array of this structure in PHP: The array $searches has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate over $searches[0] through $searches[n], but also $searches[0]["part0"] through $searches[n]["partn"]. The hard part is that different indexes ...

In a PHP5 class, when does a private constructor get called?

Let's say I'm writing a PHP (>= 5.0) class that's meant to be a singleton. All of the docs I've read say to make the class constructor private so the class can't be directly instantiated. So if I have something like this: class SillyDB { private function __construct() { } public static function getConnection() { } } A...

Using MySQLi - which is better for closing queries

I have a habit of keeping my variable usage to a bare minimum. So I'm wondering if there is any advantage to be gained by the following: $query = $mysqli->query('SELECT * FROM `people` ORDER BY `name` ASC LIMIT 0,30'); // Example 1 $query = $query->fetch_assoc(); // Example 2 $query_r = $query->fetch_assoc(); $query->free(); Now if...

Favorite PHP Library

Ok, so as my first question, I go against the FAQ rules: this is a subjective and argumentative question... Sorry for that. Anyway, I was wondering what library power PHP dev were using. Not a full framework (like cakePHP), that forces you to code and organize files in a certain way, but a library, full of useful helpers, needed function...

How to implement a web scraper in PHP?

What built-in PHP functions are useful for web scraping? What are some good resources (web or print) for getting up to speed on web scraping with PHP? ...

DOM manipulation in PHP

I am looking for good methods of manipulating HTML in PHP. For example, the problem I'm currently have is dealing with malformed html. I am getting input that looks something like this: <div>This is some <b>text As you noticed, the html is missing closing tags. I could use regex or a XML Parser to solve this problem. However, it is l...

How do I install the php_gd2 extension in MAMP on a Mac?

I'm running MAMP 1.7.2 on a Mac and I'd like to install the extension php_gd2. How do I do this? I know that on Windows using WAMP I'd simply select the php_gd2 entry in the extensions menu to activate it. How is it done when using MAMP? I know that I can do it using MacPorts but I'd prefer not to make any changes to my default OS X...

'Reliable' SMS Unicode & GSM Encoding in PHP

(Updated a little) I'm not very experienced with internationalisation using PHP, it must be said, and a deal of searching didn't really provide the answers I was looking for. I'm in need of working out a reliable way to convert only 'relevant' text to Unicode to send in an SMS message, using PHP (just temporarily, whilst a service is r...

PHP ToString() equivalent

How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: $myText = $myVar . ''; like the ToString() method in Java or .NET. ...

Does PHP have an equivalent to this type of Python string substitution?

Python has this wonderful way of handling string substitutions using dictionaries >>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rocks'} 'The Stackoverflow site rocks because it rocks' I love this because you can specify a value once in the dictionary and then replace it all over the place in the ...

Passing $_POST values with cURL

How do you pass $_POST values to a page using cURL? ...

Which PHP opcode cacher should I use to improve performance?

I'm trying to improve performance under high load and would like to implement opcode caching. Which of the following should I use? APC - Installation Guide eAccelerator - Installation Guide XCache - Installation Guide I'm also open to any other alternatives that have slipped under my radar. Currently running on a stock Debian Etch w...

PHP - Determine Parent Node Of DOMElement

I'm translating my C# code for YouTube video comments into PHP. In order to properly nest comment replies I need to re-arrange XML nodes. In PHP I'm using DOMDocument and DOMXPath which closely corresponds to C# XmlDocument. I've gotten pretty far in my translation but now I'm stuck on getting the parent node of a DOMElement. A DOMElemen...

PHP frameworks for simplifying CRUD

Based on experience which PHP framework makes implementing CRUD operations the easiest so that time can be spent on the more 'interesting' parts of the application? Suggested CodeIgniter Symfony CakePHP ATK Framework ...

Opcode cache impact on memory ussage

Can anyone tell me what is the memory usage overhead associated with PHP opcode cache? I've seen a lot of reviews of opcode cache but all of them only concentrate on the performance increace. I have a small entry level VPS and memory limits are a concern for me. ...