Tag Archives: tips

Storing HTML data in XML files, in a PHP application

Recently, I have been working on a PHP website with no SQL support (yeah, don’t ask), but needed to maintain a small database of pages and posts that could be updated via a WYSIWYG web interface. I ended up going with the following configuration:

  1. Store data in XML files.
  2. Handle XML data in PHP using the SimpleXMLElement class
  3. Allow WYSIWYG editing with CKEditor, an Javascript-based open-source text editor

This is a very simple set-up, but there are a few things to note:

Continue reading

kill -WINCH $$ to fix bash prompt wrapping to the same line

Sometimes, my bash prompt wraps long lines incorrectly, such that I’m typing over my own prompt like this:

My bash prompt is wrapping long lines onto itself! The horror!

I used to just live with it, trying to remember what I already typed and counting characters if I was going back to change something. That made my Unix experience much more frustrating that it should’ve been, because executing this single command immediately resolved the issue:

kill -WINCH $$

What does this do? You’re basically telling bash that the window size has changed. It turns out that if you resize your terminal window, bash sometimes doesn’t notice the size change without you giving it an extra nudge. Without the correct window size in hand, bash can’t wrap your text correctly!

If that doesn’t solve your bash wrapping woes, then it may be because your prompt format is incorrect. (Yup, I’ve been there, done that.) Do echo $PS1 to see what your prompt is, make changes and test drive your updated prompt by doing export $PS1='your_new_prompt_here', and save the version that makes you proud to be a shell user by putting export $PS1='your_amazing_new_prompt_here' in your ~/.bash_profile. Arabesque has a detailed guide on formatting your prompt, and Fabien Loison has way too much info about adding colour to your prompt.

Have fun at the command line!

WordPress logo

WordPress, stop inserting HTML into posts and pages!

I like to have control over all the formatting in whatever I produce — websites, documents, slideshows. This is why I write all my posts in WordPress’ text editor. I add in all the necessary HTML formatting myself. No WYSIWYG, thank you very much.

However, WordPress does this really annoying thing where it will wrap every block of text it perceives to be a paragraph in <p> tags. The key word is “perceives”, because it also wraps images, lists, and very non-paragraphy things in <p> tags. Even more frustrating is that there is no option within WordPress’ dashboard to change this setting!

BUT, we can stop this behaviour! All it takes is these two lines of code:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Insert them into your theme’s or child theme’s function.php*, and tada! Auto <p> production gone for good (until you remove those two lines from your function.php, of course).

*If you’re using a child theme and it doesn’t have a function.php, just make a new text file in your child theme’s folder and call it function.php. You don’t need to copy all the code from the parent theme’s function.php. WordPress will call whatever is written in the child’s function.php, and then whatever is in the parent’s function.php, so you won’t miss out on anything.

Smooth lines in transparent GIFs

Since I have had little experience until now in working with animated GIFs, I was horrified when I discovered that the “transparent” areas of my GIFs had terrible pixelated edges when placed over a background image. Now, I needed to use GIFs instead of PNGs because I needed the animation, and I also needed a background image instead of a solid background colour. So I started hunting on Google for a solution.

Initial searches for a solution were fruitless: Most people recommended having a solid background colour for GIFs. After rooting around a few more sites, I was beginning to wonder whether I should just add back those semi-transparent pixels from the PNG file that were lost…manually. As in, whipping out the hard-edged pencil tool and dotting in the gray dots along the image.

Thankfully, I was rescued from pixel torture by the marvels of Semi-Flattening.

Continue reading