pMachine: Stripping HTML tags in window titles

Posted by Pierre Igot in: Blogging
July 23rd, 2004 • 7:19 am

A while ago, I wrote about my (relative) confusion with the use of the cite tag and other tags typically used to quote excerpts from books, cite movie titles, etc.

One of my problems is that I want to use such tags in my blog entry titles (when citing a movie title, for example). The default behaviour in pMachine, however, is to also use the exact contents of the blog entry title for the window title in the single entry web page (the page that opens when you are viewing a single blog entry separately). And of course, in the window title, such tags are not allowed.

A reader was kind enough to provide a link (in the Comments section of the blog entry) to the W3C recommendation on this particular issue (markup in web page titles). My problem was that I didn’t have an easy solution. I could either refrain from using any tags in blog entry titles, or keep using them and force my readers to have to deal with pages with titles such as “Stanley Kubrick, <cite>Eyes Wide Shut</cite> (1999)“.

I figured, however, that stripping the code from the title when using it for the window title should be possible with some scripting. Unfortunately, I don’t know anything about PHP. So I posted an inquiry on the pMachine forums.

Chris Curtis, one of the pMachine guys, was kind enough to provide me with a solution within 24 hours. Instead of using:

<?php show_field($id,"title"); ?>

in my web page file, I tried using:

<?php

ob_start();
show_field($id,"title");
$title = ob_get_contents();
ob_end_clean();

echo strip_tags($title);

?>

And sure enough, it works! Now I have the best of both worlds. I can use tags in my blog entry titles, and the tags will be rendered properly when displaying the actual title as a heading in a web page, but they will stripped when using the title as the window title for the web page. Great!

And Chris Curtis and pMachine should be commended for providing such support.


Comments are closed.

Leave a Reply

Comments are closed.