php

Retrieve all nodes in a tree that are children of another one

(Before you down mod it: nope, this is not homework) I have a web system which has a classical parent-children menu saved in a database, with fields id as the PK, and parent_id to pointing to the owning menu. (Yes, I know this doesn't scale very well, but that's another topic). So for these records (id-parent_id pairs): 0-7 0-4 4-9 4...

Are there any Parsing Expression Grammar (PEG) libraries for Javascript or PHP?

I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with. Does anyone know of any PEG l...

What is the best way to change the encoding of text in PHP

I want to run text through a filter to ensure it is all UTF-8 encoded. What is the recommended way to do this with PHP? ...

How to Truncate a string in PHP to the word closest to a certain number of characters?

I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters. I could use substr() to chop off the text at 200 chars, but the re...

Using x_sendfile with Apache/PHP

I can't seem to find much documentation on x_sendfile or example code for PHP (there is some rails code). Anyone use it before and would mind giving a quick snippet of code and a brief description? ...

mysqli_statement::num_rows() returns the wrong value

I was writing a database handler class in PHP using the mysqli class and prepared statements. I was attempting to print out the result. It didn't work right off the bat so I decided to do some debugging. I tried to use the num_rows() method from the mysqli_statement class, but it kept returning 0. I decided to write a small porti...

How do you convert 00:00:00 to hours, minutes, seconds in PHP?

I have video durations stored in HH:MM:SS format. I'd like to display it as HH hours, MM minutes, SS seconds. It shouldn't display hours if it's less than 1. What would be the best approach? ...

PHP debugging on OS X - hopeless?

I have tried: Xdebug and Eclipse. Eclipse launches a web browser, but the browser tries to access a non-existent file in Eclipse's .app bundle. Xdebug and NetBeans. It does a little bit better; a browser opens a page in /tmp which says "Launching. Please wait…" but nothing happens beyond that. Xdebug and debugclient, the CLI tool which...

Given two dates what is the best way of finding the number of weekdays in PHP?

The title is pretty much self explanatory. Given two dates what is the best way of finding the number of week days using PHP? Week days being Monday to Friday. For instance, how would I find out that there are 10 week days in between 31/08/2008 and 13/09/2008? ...

How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?

Can you explain the difference between == and ===, giving some useful examples? ...

Zend Framework Select Operator Precedence

Hi everyone, I am trying to use Zend_Db_Select to write a select query that looks somewhat like this: SELECT * FROM bar WHERE a = 1 AND (b = 2 OR b = 3) However, when using a combination of where() and orWhere(), it seems impossible to use condition grouping like the above. Are there any native ways in Zend Framework to achieve the ...

Spelling Alternatives based on a Database?

I'm looking for an efficient way (using PHP with a Mysql Database) to suggest alternative spelling for a query. I know I can use services such as Yahoo's Spelling Suggestion but I want the suggestions to be based on what is currently available in the database. For example: The user has to fill a form with a "City" field, and I want to...

MDB2 disconnects and forgets charset setting when reconnecting

We recently debugged a strange bug. A solution was found, but the solution is not entirely satisfactory. We use IntSmarty to localize our website, and store the localized strings in a database using our own wrapper. In its destructor, IntSmarty saves any new strings that it might have, resulting in a database call. We use a Singleton ...

How to start facebook app?

Just want to know what is better way to get start developing faccebook app?Any tutorial recommnedation?And which is better to start up -php or rails? ...

Sending 'application/javascript' MIME t Type Header Causes 500 Error with PHP5 & IIS7

I have a script that works fine on my test server (using IIS6). The script processes an ajax request and sends a response with the following line: header( 'application/javascript' ); But on my live server, this line crashes the page and causes a 500 error. Do I need to allow PHP to send different MIME types in IIS7? If so, how do I do...

Easy way to export a SQL table without access to the server or phpMyADMIN

I need a way to easily export and then import data in a MySQL table from a remote server to my home server. I don't have direct access to the server, and no utilities such as phpMyAdmin are installed. I do, however, have the ability to put PHP scripts on the server. How do I get at the data? I ask this question purely to record my way ...

PHP - RSS builder

Hello, I have a old website that generate its own RSS everytime a new post is created. Everything worked when I was on a server with PHP 4 but now that the host change to PHP 5, I always have a "bad formed XML". I was using xml_parser_create() and xml_parse(...) and fwrite(..) to save everything. Here is the example when saving (I read...

Connecting to Oracle using PHP

I am a PHP Developer, but I am confused on how to connect to a remote Oracle database instance from PHP. I simply need to query a read only database and get some data. Do I need to have the Oracle Instant Client or the extension is enough? Thanks. ...

PHP/mySQL - regular recalcuation of benchmark values as new users submit their data

I am confronted with a new kind of problem which I haven't encountered yet in my very young programming "career" and would like to know your opinion about how to tackle it best. The situation A research application (php/mysql) gathers stress related health data from users. User gets a an analyses after filling in the questionnaire. Valu...

strpos function problem in PHP not finding the needle

In php I have open a .php file and want to evaluate certain lines. Specifically when the $table_id and $line variables are assigned a value. Within the text file I have: ... $table_id = 'crs_class'; // table name $screen = 'crs_class.detail.screen.inc'; // file identifying screen structure ... amongst other l...