Blog
-
Remove Rubbish Microsoft Markup
This is an amendment to the function I wrote to fix the broken characters that Microsoft Office inserts into content that you paste into your CMS. The update adds an optional parameter to the function that can strip out the MS-specific styles that are only recognised by IE and cause display issues in other browsers. The problems caused by Microsoft because of this have been quite large, and have…
-
Creating Select Lists with Default Options
Select lists are great, but what happens when your visitor has made a mistake in the form and you need to re-display the form, along with the option they just selected? This is where PHP, comes in. Now, depending on how your site is set up, you might be creating the select list from either a database or other source, but at some point it will be in a form that you can loop though. For this example…
-
Stylesheet Switcher
One drawback to alternate stylesheets on a website is that no browser I've seen allows the newly selected stylesheet to persist through the browsing of that site. As you move from page to page, the default style takes over again. This was particularly annoying for me, as I was in the middle of testing out a new stylesheet on my site as a demonstration, and each time I navigated to a new page, I'd have…
-
Nested Lists with Overriding Styles
Nested tree menus are often a useful way of portraying hierarchical data, and are most commonly used to display directory trees to a user. Semantically, the best way to create them is with proper list markup. The problem with nested lists, is that, by default, they all have the same amount of padding, which is often annoying for the topmost list item. What might seem an obvious solution is not the…
-
Using cURL to Interface with Twitter
Twitter. Love it or hate it, it's here to stay for a while. One recent project I worked on required some integration between Twitter and the website in I was working on. Having only a short while to work on this, and not being familiar with any of the various plugins out there, I wrote a simple function using cURL. While this example will focus on grabbing the number of followers of MicroMart magazine…
-
CSS Media Types
CSS Media Types CSS is a wonderful thing, but most people only ever use it for styling HTML on a regular computer screen. The fact is, CSS has, right from the beginning, had a much wider potential audience. The following code excerpt shows you how you might use alternative stylesheets for rendering your web page on some form of media that isn't a compupter screen: <link rel="stylesheet" type=…
-
Change Selected Text Colours
::selection { background-color: #f00 !important; color: #fff !important; } ::-moz-selection { background-color: #f00 !important; color: #fff !important; } It can be frustrating sometimes to design a website, only to have the operating systm of a visitor change a bunch of the colours it uses for everything. One annoying example is the text selection colours. Thankfully, CSS can help…
-
Popups That Always Work
"My popup windows don't work with Javascript turned off. How can I make them always work?" This is a question I see fairly frequently popping up on forums and mailing lists. Popup windows can be a pretty useful thing when used correctly, but in terms of accessibility, relying on Javascript for navigation is a bad thing. There is a way that you can still use that popup, without causing problems for…
-
Listing Directories In An FTP Location
A question that I saw recently on a mailing list was how to determine whether a file (I'll use the Unix terminology here: everything is a file) on an FTP connection is a directory or a file. One suggestion was to use the FTP file wrapper in PHP and then use the is_file() and is_dir() functions to determine the type. I noted at the time that this wasn't a perfect solution, as it relied on the FTP file…
-
Pass Values by Reference in foreach Loops
Quite often, the question comes up about how to modify elements of an associative array inside a foreach loop, because the foreach loop passes by value, essentially creating a duplicate array in memory which your code works on. While this is usually not an issue, it can be if you want to actually modify the array. There are two ways in which you can do this, use the key of each element to modify the…
-
Streaming Files for Security
Picture the scenario: You've just set up a social networking site for your niche hobby of collecting old tin cans. Part of the site is an image gallery that allows members to upload pictures of their collections. You want to make sure that only members can see these images, but how? Preventing access to a page that contains the image is easy, but what if they try to link to the image directly? One…
-
Replacing Non-Displaying MS Word Characters
I work on a lot of CMS's, and website content generally follows the same general process: Original copy is written, and saved as an MS Word document. This file is sent on for review and final edits. Content from final version is copied and pasted directly from Word into the CMS. Now generally, this process is fine. However, if any of a number of particular characters was used in the original…
-
Alternate Table Rows in PHP
I often see people asking around on forums and mailing lists, how best to create tables with alternate rows, and I often see a variety of methods, many of which are quite frankly scary! Sure, CSS3 has a pretty nifty solution in the form of the nth-child selector, but this has limited browser support (currently, it is not recognised by Firefox 2 & 3 or IE 6 & 7), and CSS3 has not yet been fully…