php posts page 4

PHP: Outputting Lists in Arbitrary Number of Columns

For lists of narrow pieces of content, it can make sense to put them in multiple columns to better use available space. For things like image galleries (a list of images), where it tends to be easier to read from right to left, or when order is irrelevant, it is easy to turn a regular list into columns (like a grid in the case of the images) by simply making each item a fixed width and height and then floating the items left. This works fine back to IE6 and remains fully semantic and accessible as one list.

Text lists tend to be easier to read top to bottom though, so when they are in alphabetical or some other important order, it is generally better to order them top to bottom in each column. I haven’t delved into the CSS3 multi-column layout abilities yet, as that is not widely supported (especially no IE). The float item method cannot be made to appear in the proper order while truly keeping the items in proper order in the list for accessibility and semantics, and putting the data in the proper improper order to make that work would be complicated anyway. The only real way I am aware of to currently make the columns be in proper order is to separate the list into a list for each column and then float each column left. This is not ideal semantically and for accessibility, but will still read in the proper order for all users.

Continue reading post "PHP: Outputting Lists in Arbitrary Number of Columns"

PHP Functions: Array as Argument

A while back, I wrote about using the JSONesque literal value parameters in Javascript, like jQuery does. This allows arguments to be passed: with names, in no particular order, all being optional. I set it up so that multiple arguments could be used as well, allowing for existing functions to still work or people who prefer that syntax to have it. I will now write about something similar for PHP.

In PHP, it is not quite as elegant, but almost. An array with key-value pairs is passed as the single argument for named argument mode. So you could call like this:

testFunction(array("arg1"=>"value1","arg3"=>"value3","argCallback"=>"testCallback"));

or with regular arguments:

testFunction("value1",null,"value3","testCallback");
Continue reading post "PHP Functions: Array as Argument"

PHP Parser for RSS Feed From WordPress.com

I’ve been working on my own site a bit since getting out of school. I’ve been pulling an RSS feed from this blog onto my homepage for a while now, using something based off of this script. I try to keep the markup valid. The feed has given me a bit of troubles for valid markup, mainly with escaping ampersands. One problem was that I was using this function:

function pagFixRSSEncoding($argString){
    return mb_convert_encoding($argString,'HTML-ENTITIES', 'UTF-8');
}

which I had gotten from somewhere. I’m not sure what it does, but it seems to do nothing for me. I removed it, though I’ll reinstate it or look for something else if characters other than ampersands give me trouble.

I was also using this function:

function pagFixLinks($argString){
    return str_replace("&", "&", $argString);
}

to fix the ampersands in the “link”. This simply replaces all ampersands with the proper HTML entity in the passed string, works just fine.

Continue reading post "PHP Parser for RSS Feed From WordPress.com"