xiven.com stating the blatantly obvious since 2002

More invalid HTML/XHTML problems

I was just playing around with the highlight_file() function in PHP. Lovely function except it's putting <font> tags in (urrghhh). So after a little playing around I made a little bit of code to sort it out.

The following code will reformat the output from the highlight_file() function into valid XHTML (removes <font> elements, replaces with <span> <code> ). It also makes use of the <pre> tag instead of all those &nbsp; and <br /> tags being in there.

Note: It has since been brought to my attention that using <code> tags is more semantically correct than <span> (thanks David) so the code below has been updated to do just that.


<style type="text/css">
  .source code.html { color: <?=ini_get('highlight.html')?>; }
  .source code.default { color: <?=ini_get('highlight.default')?>; }
  .source code.keyword { color: <?=ini_get('highlight.keyword')?>; }
  .source code.string { color: <?=ini_get('highlight.string')?>; }
  .source code.comment { color: <?=ini_get('highlight.comment')?> }
</style>
<?php
echo '<pre class="source">';
$source = highlight_file('xxx.php', true);
$search[0] = '<font color="'.ini_get('highlight.html').'">';
$search[1] = '<font color="'.ini_get('highlight.default').'">';
$search[2] = '<font color="'.ini_get('highlight.keyword').'">';
$search[3] = '<font color="'.ini_get('highlight.string').'">';
$search[4] = '<font color="'.ini_get('highlight.comment').'">';
$search[5] = '</font>';
$search[6] = '<br />';
$search[7] = "\r";
$search[8] = '&nbsp;';
$replace[0] = '<code class="html" xml:lang="x-html">';
$replace[1] = '<code class="default" xml:lang="x-php">';
$replace[2] = '<code class="keyword" xml:lang="x-php">';
$replace[3] = '<code class="string" xml:lang="x-php">';
$replace[4] = '<code class="comment" xml:lang="x-php">';
$replace[5] = '</code>';
$replace[6] = "\n";
$replace[7] = '';
$replace[8] = ' ';
echo str_replace($search,$replace,$source);
echo '</pre>';
?>

Yes, some code very much like this was used to make the above listing of the code look nice, and yes, the real reason why I made this post was to test it out... :)

Posted: 2002-12-18 18:03:37 UTC by Xiven | Cross-references (0) | Comments (2)

Pingback revisited

I just upgraded my Pingback server to include logging of all attempts (successful or not) to pingback me so I can see when its broken. I also decided that I really should release my pingback server source code since the server is (according to some people) the hardest part to do (you'll need these XML-RPC functions also). I won't release the client stuff yet since my code for that sucks. Well, more. ☺

Posted: 2002-12-17 16:46:21 UTC by Xiven | Cross-references (0) | Comments (0)

Be afraid...

Kamakaze has decided to put his humour into comic strip form. Actually it's quite an amusing little strip, though you really have to have played Voidwars to truly appreciate it.

Posted: 2002-12-16 02:34:39 UTC by Xiven | Cross-references (0) | Comments (0)

Style is everything

I've just added a couple of new alternate stylesheets to this site (a "High visibility" one which makes the pale blue into a very very bright blue, and a "Printable" one which lays out the page in a more printer-friendly way) so if your browser supports alternate stylesheets (currently only Opera 7 Beta and Mozilla are known to do this), by all means try them out or ignore them at your convenience.

In other news, this site now conforms to the W3C-WAI Web Content Accessibility Guidelines 1.0 (Level AAA). At least that's the theory anyway. Please feel free to let me know if you think I've missed something.

Further information on accessibility for this website.

Posted: 2002-12-15 13:30:57 UTC by Xiven | Cross-references (0) | Comments (0)

Q Who?

In the continuing saga of "Things I hate about Internet Explorer", today I tackled the issue of IE's screwed support of the <q> tag (specifically that it won't add the quotes in like it's supposed to).

Abandoning the <q> tag altogether is unacceptable in my opinion (though obviously for some people it is the only way to get around the problem), so now all weblog posts get quotes (") automatically added inside any <q></q> tag iff it detects that the user is using IE (otherwise it leaves it well alone). For outside of the weblog, I made a small PHP function to perform the same task. This I suppose, is one of the advantages of dynamically generating all your pages.

If only we didn't have to do such silly things to work around browser bugs.

Posted: 2002-12-12 16:42:58 UTC by Xiven | Cross-references (0) | Comments (0)