xhtml valid hack released!

Date 2006-03-21 01:43:00 | Category: XOOPS

in englishin japanese
XHTML ValidでないサイトをValidにするHackです!
やり方は、include/ フォルダに joke_xhtml_valid.php を用意して、mainfile.php のXOOPS_ROOT_PATH定義行の直後に1行加えるだけ!

……な〜んて、もちろん冗談ですが、このサイトみたいに、xhtml validをまったく気にしていないサイトでは、とりあえずhtml-lintで10〜20点は上昇しましたよ
A line insertion into mainfile.php

	define('XOOPS_ROOT_PATH', '...');
	require XOOPS_ROOT_PATH.'/include/joke_xhtml_valid.php' ;


include/joke_xhtml_valid.php

<?php

ob_start( 'joke_xhtml_valid' ) ;


// ob filter
function joke_xhtml_valid( $s )
{
	$s = str_replace( '<br>' , '<br />' , $s ) ;
	$s = str_replace( '<hr>' , '<hr />' , $s ) ;
	$s = str_replace( '<br /><br />' , '<br />' , $s ) ;
	$s = preg_replace_callback( '/\<img [^>]+\>/' , 'joke_xhtml_valid_img_alt' , $s ) ;
	$s = preg_replace_callback( '/\<table [^>]+\>/' , 'joke_xhtml_valid_table_summary' , $s ) ;
	return $s ;
}

function joke_xhtml_valid_img_alt( $matches )
{
	if( stristr( $matches[0] , 'alt=' ) ) {
		return $matches[0] ;
	} else {
		return '<img alt="" ' . substr( $matches[0] , 5 ) ;
	}
}

function joke_xhtml_valid_table_summary( $matches )
{
	if( stristr( $matches[0] , 'summary=' ) ) {
		return $matches[0] ;
	} else {
		return '<table summary="dummy" ' . substr( $matches[0] , 7 ) ;
	}
}
?>




You can read more news at PEAK XOOPS.
http://xoops.peak.ne.jp

The URL for this story is:
http://xoops.peak.ne.jp/md/news/index.php?page=article&storyid=87