Tags

Posts tagged with: php

ajax analysis api apple atom automator backpack browsers camping cheatsheets code console editors ergonomics gems google helipad hpricot internationalisation javascript lies mac optimisation patterns performance personal php plugins productivity programming prototype rails rapidrails rsi rss ruby server snippets standards sysadmin terminal testing textile textmate theory tips tools vim workshops writing xslt

PHP 5's anonymous functions

Posted on Wed 5 Apr, 2006

I don’t see much use of anonymous functions in php, yet when I write python or ruby, I use constructs like this quite often. You can do it in php though, with create_function. It’s nothing that fancy, it just lets you create a function whenever you feel like it. This can be placed wherever you need a callback in php.

Callbacks in php must be a function name. You can’t refer to methods in the current class, or hack it by making a function that returns an object: function()>probably_a_singleton>hello(). This is where create_function() comes in.

Here’s an example:

$where_sql[] = ” $...

Continue reading → | Tagsphp, programming

Using XSLT with bad HTML

Posted on Tue 19 Oct, 2004

We have a PHP CMS with a lot of poorly written HTML in the client-contributed content. This kept causing my XSL template system to output XML errors. I got around this problem by:

  1. wrapping content in CDATA tags
  2. Checking if the content is valid XML with xml_parse() in PHP, if not I add a CDATA tag and try again.
  3. Strip out bad characters that may have crept in from Word
  4. Process the XSL and XML using xsl:value-of tags with disable-output-escaping=”yes”

Using CDATA tags around unpredictable HTML helps prevent problems with the XML parser. Without the final step, the resulting HTML

Continue reading → | Tagsphp, xslt, programming

Internationalisation with XSLT

Posted on Mon 2 Aug, 2004

I’ve found two approaches to this:

http://sources.redhat.com/ml/xsl-list/2000-08/msg01318.html

http://www-106.ibm.com/developerworks/library/wa-xslt/

I think the second method looks like the best. I like the idea of using a general XSLT template to add in generic functionality too.

Continue reading → | Tagsxslt, php, internationalisation

Processessing multiple XML files with XSLT in PHP

Posted on Fri 16 Jul, 2004

I often use a message class for a lot of things with PHP. This allows me to build messages to display to the user for errors, successes and general feedback.

Classes for each of these three things are created in CSS to display the information, and then I use a simple PHP class for appending messages to a arrays.

I wanted to include this in some XML data I was processing with XSLT, but I found it difficult to combine multiple XML files with PHP’s XSLT processor. However, in PHP4, you can do it like this:

// this is a code fragment
//
$XML = implode('', file($XML_Fi...
Continue reading → | Tagsphp, xslt, programming, snippets, tips