php

PHP Array To XML

I needed a quick, perhaps even sloppy way to output an array as XML. Some Googling turned up a few tools, including Simon Willison’s XmlWriter, Johnny Brochard’s Array 2 XML, Roger Veciana Associative array to XML, and Gijs van Tulder’s Array to XML. Finally, Gijs also pointed me to the XML_Serializer PEAR Package.

In an example of how even the smallest barriers can turn people away, I completely ignored the two possible solutions at PHP Classes, because navigating and using the site sucks. I passed on Willison’s function because, well, it didn’t look like it would do enough of what I wanted. Despite Gijs’ recommendation of the PEAR module, I was happy enough to use his array_to_xml function, as it did what I needed and required the lest work for the moment. I may revisit XML_Serializer sometime, but…

Dang addslashes() And GPC Magic Quotes

Somewhere in the WordPress code extra slashes are being added to my query terms.

I’ve turned GPC magic quotes off via a php_value magic_quotes_gpc 0 directive in the .htaccess file (we have far too much legacy code that nobody wants to touch to turn it off site-wide). And I know my code is doing one run of addslashes(), but where are the other two sets of slashes coming from?

T2000 Unboxed And Online

My Sun T2000 is here, and with Cliff‘s help it’s now patched, configured, and online. (Aside: what’s a Sun Happy Meal?) I’ll second Jon‘s assessment that Sun really should put some reasonable cable adapters in the box, as the the bundle of adapters necessary to make a null modem connection to the box is ridiculously […] » about 200 words

PHP5’s SimpleXML Now Passes CDATA Content

I didn’t hear big announcement of it, but [deep in the docs][1] (? PHP 5.1.0) you’ll find a note about [additional Libxml parameters][2]. In there you’ll learn about “LIBXML_NOCDATA,” and it works like this:

simplexml_load_string($xmlraw, ‘SimpleXMLElement’, LIBXML_NOCDATA);


Without that option (and with all previous versions of PHP/SimpleXML), SimpleXML just ignores any < ![CDATA[...]]> ‘escaped’ content, such as you’ll find in most every blog feed.



 [1]: http://us3.php.net/manual/en/function.simplexml-load-string.php
 [2]: http://us3.php.net/manual/en/ref.libxml.php#libxml.constants "additional Libxml parameters"

Performance Optimization

A couple notes from the past few days of tweaks and fixes:

  • Hyper-threading has a huge effect on LAMP performance.
     
  • From now on, I’ll have bad dreams about running MySQL without Query Caching in the way that I used to have nightmares about going to school wearing only my underwear. The difference is that big.
     
  • WordPress rocks, but it has some queries that will kill large databases. I’m playing with baseline when I fix ’em, but it’s worth it.
     
  • Being highly ranked for searches related to bears and bear lovers on the weekend that Grizzly Man airs on TV is both good and bad: it doubled my previous high for daily page-loads, but killed my server and taught me some lessons about sloppy coding.
     
  • The support techs are Lunarpages continue to pretty much rock.
     
  • Having friends who cut their teeth on high-performance PHP/MySQL and are willing to spend the night workshopping it with you is indispensable.
     
  • It’s hard to beat the calming beauty of driving home through a snowfall on back roads at 2 AM carried by your life’s soundtrack.
     

Using XML In PHP5

Everybody likes documentation. The Zend folks posted this overview and SimpleXML introduction The O’Reilly folks at ONLamp offered this guide to using SimpleXML. Of course, there’s always the SimpleXML docs at PHP.net.

Two problems: I haven’t encountered CDATA in my XML yet, but I do hope to develop a better solution than offered here when I do. The other is that SimpleXML chokes on illegal characters, a unfortunately common occurrence in documents coming from III’s XML Server.

I Will Crush You

Or, er, my server will be crushed. I guess I should admit that my stuff could do with some optimization, maybe. Perhaps what I really need is something faster than Celeron with 512MB RAM. Maybe. tags: 512mb ram, apache, break point, breaking point, celeron, crushed, load average, mysql, php, server, top, web server » about 100 words

Library-Related Geekery

Ryan beat me to reporting on the interesting new services at the Ockham Network (noted in this Web4lib post). The easiest one to grok is this spelling service, but there are others that are cooler. He also alerted me to a Perl script to proxy Z39.50 to RSS. Though for those more into PHP (like […] » about 300 words

PHP Developer Resources

Somebody asked for some links to get started with PHP. Of course I lead them to the PHP.net official site, where the documentation is some of the best I’ve seen for any product.

I also suggested PHPDeveloper.org and PHPFreaks.com, though the truth is I usually Google any questions I have that the official docs don’t answer. Still, I’ve found some good info at both of those.

Finally, the PHP Cheat Sheet at ILoveJackDaniels.com is pretty nice to have around (cheat sheets mentioned previously).

XML/PHP/SWF Charts

Flash app dynamically generates charts based on XML formated data or values in a PHP array.

XML/SWF Charts is a simple, yet powerful tool to create attractive web charts and graphs from dynamic XML data. Create an XML source to describe a chart, then pass it to this tool’s flash file to generate the chart. The same tool also accepts PHP sources. XML/SWF Charts makes the best of both the XML and SWF worlds. XML provides flexible data generation, and Flash provides the best graphic quality.

More info here.

WordPress’ is_X() function

An entry at the WordPress support forums{#13505} gave me the list I needed. How do they work?

“You can use [these] in a conditional to display certain stuff only on [certain] page[s], or to omit certain stuff on [those] page[s].”

Here’s the list:

  • is_404()
  • is_archive()
  • is_author()
  • is_category()
  • is_date()
  • is_day()
  • is_feed()
  • is_home()
  • is_month()
  • is_new_day()
  • is_page()
  • is_search()
  • is_single()
  • is_time()
  • is_year()

So there you go.