Simon Willison’s Weblog

Subscribe
Atom feed for php

177 posts tagged “php”

2003

HttpClient PHP class

I’ve been working in quite a roundabout fashion recently. My principle target is to build a collaborative blogging system. As part of this, I needed an RSS aggregator to allow a single blog to show the most recent entries from a number of other, related blogs. Then I needed a way of downloading RSS feeds from external sites. While thinking about this (although to be fair it’s pretty much a solved problem) I was inspired to build something that could cache whole sites. And that lead me to need a PHP HTTP client class for retriving information from the web. So I wrote one of those :)

[... 381 words]

A PHP Installer

Wez Furlong is working on a generic PHP installation script. If he finds a nice solution to the safe_mode and open_basedir restrictions mentioned in his post this could be a hugely useful tool for the PHP community.

Some PHP notes

I ran an intermediate to advanced PHP session at University today, on behalf of BCSS. The turn out wasn’t particularly impressive, probably because the only lecture today had been cancelled so there were a lot fewer people from our course on campus than I had expected (the session was arranged because a piece of group coursework we are working on at the moment uses PHP). The notes I put together from the course are available online. They were put together in a bit of a hurry, so please tell me if you spot any mistakes. Topics covered include sessions and cookies, classes and objects, references and some brief notes on writing secure code.

PHP and Javascript spell checker

Last week I commented that Sam Ruby’s spell checking feature could be made even funkier with the addition of a javascript powered “corrections” menu. I spent a few hours this afternoon playing with the idea, and I’ve now got quite a nice proof of concept:

[... 186 words]

Hashing client-side data

Via Scott, a clever PHP technique for ensuring data sent to the browser as a cookie or hidden form variable isn’t tampered with by the user:

[... 248 words]

2002

One time URLs with PHP

Generating One-Time URLs with PHP has some simple example code which demonstrates PHP’s file locking functions in action.

PHP for the enterprise

PHP5: Ready For The Enterprise? (via Scott) discusses forthcoming improvements in PHP5 and asks if they will lead to acceptance of PHP as a suitable language for enterprise applications. It looks like a killer factor could well be PHP’s improved Java and .NET integration abilities. Write the back-end in Java/.NET and use PHP for the front end—that way you get a powerful web-specific scripting language for the front end of your site. Then if you ever need to change technologies on the back end your front end code can be reused.

The evolution of PHP

Via ReadingEd, an interesting article on the Object Oriented Evolution of PHP by Zeev Suraski (the Ze in Zend). As well as a history of PHP’s OO support, the article provides some tasty snippets of information as to improvement to look forward to in PHP 5. Personally I can’t wait for the objects to default to passing by reference, but the exception handling is going to be very nice as well:

[... 209 words]

PHP training update

The aforementioned PHP training system was a mixed success. On the one hand, I discovered that trying to teach a room full of people is a lot tougher than I had expected (to cut a long story short, I stumbled through about five minutes of reiterating the same few points before all present agreed that the session would be best run using the ask-questions-when-you-get-stuck format). Luckily I had prepared some pretty comprehensive support material the night before. I’m chalking that one down to experience.

phpPatterns

phpPatterns is a brand new site which advocates and documents the use of object oriented design patterns with PHP. It’s a great concept and the site already has some impressive content (although it could really do with a PHP references tutorial). The site is a project of Harry Fuecks, a regular contributor to SitePoint’s PHP forums.

Funky caching explained

I didn’t take much notice of “funky caching” while reading through Rasmus Lerdorf’s PHP tips and tricks presentation—I saw that it was talking about using custom 404 pages to serve up dynamic content depending on the URL and wrote it off as a hack that, while useful, was fundamentally flawed in that it would add an error log entry whenever a page was served.

[... 208 words]

PHP tips and tricks from Rasmus

Rasmus Lerdorf has published a PHP Tips and Tricks PDF based on a presentation given at the recent PHPCon2002. The file is a veritable goldmine of useful information, covering topics including optimisation, sessions, security, dynamic image/flash/PDF generation and using Squid and MySQL replication to increase the performance of a high traffic site. Spotted on PHPDeveloper.org.

Partner as a case study

I’ve been helping my partner Natalie Downe recreate her site using CSS and structural markup. She’s new to web design and has been taking to CSS like a duck to water—as a veteran of Microsoft Word globally defined styles come to her naturally and she took very little time to cotton on to the importance of seperating presentation from content. I’ve shown her tables as well but she isn’t really interested as she sees CSS as a much better solution for general presentation. I’m hoping to help run an HTML/XHTML/CSS training course at the University early next year with a heavy emphasis on structural markup, standards compliance and accessibility so it’s great to have a guinea pig to play with :)

[... 203 words]

Zend re-design... terrible!

Zend (the commercial company behind the PHP scripting language) have launched a redesign of Zend.com. My verdict on the new design ... terrible.

[... 161 words]

Software Engineering practises for PHP

Scott Johnson’s presentation on Software Engineering Practices for Large Scale PHP Projects is fantastic—lots of excellent practical advice for professional development with PHP. It’s a shame the presentation slides require Internet Explorer (due to being exported from Power Point) but it was more than worth firing up IE to view them.

PHP at Yahoo

Making the Case for PHP at Yahoo! (via Jeremy Zawodny) looks like it was a great presentation. The slides include the reasons PHP was chosen over ASP, ColdFusion, JSP and Perl and has some interesting details on the history of Yahoo’s server side technologies. Jeremy has extensive coverage of PHPcon so be sure to flick through some of his recent entries while you are there.

Advanced PHP resources

HarryF on the SitePoint forums has compiled a fantastic list of Advanced PHP Resources, with links to sites covering object orientation, general application design, n-tier layering and using PHP with XML.

Sensible URLs with PHP

Brent Simmon’s Law of CMS URLs:

[... 187 words]

Two new web services

I’ve implemented two example web services to demonstrate the Incutio PHP XML-RPC library’s capabilities. The services allow you to search and retrieve articles from FOLDOC and the Jargon File, two popular freely available online dictionaries.

[... 349 words]

New version of IXR

Announcing beta 1.5 of IXR, the Incutio XML-PRC Library for PHP. The library has undergone a complete restructuring and has a much cleaner design as a result. It also has a huge stack of new features, including:

[... 96 words]

A new XML-RPC library for PHP

I spent most of yesterday messing around with XML-RPC. There are a variety of XMl-RPC libraries available for PHP but none of them felt right for what I needed. So, I’ve written my own.

[... 115 words]

Grabbing web pages with Perl and PHP

Web Basics with LWP (via Scott) is an excellent tutorial on Perl’s LWP, a powerful set of modules which make it easy to retrieve content from the web. I’ve been using the excellent Snoopy class for PHP for the same purpose, but I have to admit it isn’t half as comprehensive as LWP. I’ve also written my own simple function safeGet for more light weight tasks—it grabs and returns the contents of a web page but limits both the size of the page and the maximum time it can take to download it.

PHP XML-RPC

I’ve been playing with XML-RPC and PHP today. I ended up using Keith Devin’s pleasantly straight forward library thanks to PHP’s built in (and completely undocumented) XML-RPC support conflicting with the function names used by Useful Inc’s partially object oriented library. I’ve been messing around with Stuart’s idea for a trackback alternative and things are looking pretty promising.

Templating with Smarty

Zend have a short tutorial on PHP Templating with Smarty.

PHP generated PDFs

R&OS PDF PHP classes (via tidak ada). This is the most useful PHP library I’ve seen in a long time. It allows dynamic generation of PDF files without needing any additional modules installed on the server (although GD is required if you want to add images to your PDFs). It is extremely easy to use and has an impressive set of features, including PDF drawing tools, built in page number support and excellent documentation. On the topic of PDFs, Yes You Can advocates their use for presentations and touches on a method of generating them using Python.

PHP immune to SQL injection attacks

An interesting thread on SitePoint about SQL injection attacks. One of the points brought up is that PHP is by default virtually immune to injection attacks thanks to magic quotes (discussed here yesterday).

Magic quotes solution

Pink Goblin (otherwise known as HarryF) explains why magic quotes are evil. This is an issue that every PHP developer should be aware of, as it can cause all kinds of problems in your scripts if you ignore it. He suggests using a custom myAddSlashes() function which only calls addslashes() if magic quotes are turned off. I have an alternative solution—chose your preferred setting (quotes on or off) and apply it at run time to all incoming data in one go. My code for doing this is available here. By a bizzare coincidence I wrote the script this morning, then spotted a link to the Pink Goblin article on tidak ada literally five minutes after finishing it.

PHP numbered code listings

Michael V has written a couple of functions to apply my CSS numbered code listing technique to PHP’s built in syntax highlighting.

PHP and ID3 tags

MP3 Piranha is a clever application which indexes your MP3 collection and uses the Amazon Web Service API to look up the album cover, related albums and provide a link to buy the album from Amazon. Out of curiosity, I ran a search for a PHP library to decode ID3 tags to see if such a thing could be built with PHP, and came up with this script by Leknor. The class is well written and I learnt a lot about ID3 tags looking through it—it seems they take up the last 128 bytes of an MP3 file and can be decoded using PHP’s unpack() function.

PHP strings tip

PHP Tip: You can access characters within a PHP string using the index of the caracter in curly braces after the variable name. For example, $string{0} returns the first character, $string{3} returns the fourth character and $string{strlen($string)-1} returns the last character. You can assign to individual characters of a string in the same way, so $string{0} = strtoupper($string{0}); will convert the first character of a string to upper case. For more tips on working with strings see the PHP manual and Zend’s useful strings tutorial.