download this file: func.html.php view text/plain: func.html.php file encoding: EUC-KR [goback]
<?php
##
## this file name is 'func.html.php'
##
## html functions
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2010.04.20 : some code-style change
##  - 2002.05.12 : fixed bug
##  - 2003.03.05 : new build
##
## [references]
##
## [usage]
##
## [example]
##

## get html forom size
##
## SORCE : JSBOARD
##
function form_size($size$print 0)
{
  if(!
$agent = & $GLOBLAS['_agent'] && !$agent $GLOBALS['agent'])
  { 
$agent get_agent(); }

  
## À©µµ¿ì¿ë ³×½ºÄÉÀÌÇÁ
  ##
  
if($agent['br'] == 'NS' && $agent['vr'] == 4)
  {
    if(
$agent['os'] == 'NT')
    {
        if(
$agent['ln'] == 'KO'$size *= 1.1// ÇÑ±ÛÆÇ
        
else $size *= 1.4;
    }
    else if(
$agent['os'] == 'WIN')
    {
        if(
$agent['ln'] == 'KO'$size *= 1.1// ÇÑ±ÛÆÇ
        
else $size *= 1.3;
    }
    else if(
$agent['os'] == 'LINUX')
    {
        if(
$agent['ln'] == 'KO'$size *= 2.8// ÇÑ±ÛÆÇ
        
else $size *= 1.0;
    }
  } else

  
## ³×½ºÄÉÀÌÇÁ 6 or Mozilla
  ##
  
if($agent['br'] == 'MOZL' || ($agent['br'] == 'NS' && $agent['vr'] == 6))
  {
    if(
$agent['os'] == 'NT')
    {
        if(
$agent['ln'] == 'KO'$size *= 2.2// ÇÑ±ÛÆÇ
        
else $size *= 1.8;
    }
    else 
$size *= 2.6;
  }

  else if(
$agent['br'] == 'LYNX'$size *= 2;
  else if(
$agent['br'] == 'KONQ'$size *= 2.6;

  return 
intval($size);
}

## example :
##    $i = 0;
##    $cols = 4;
##    while(...)
##    {
##        $tr = get_tr_tag($i,$cols);
##        echo $tr[0].'<TD>...</TD>'.$tr[1];
##        $i++;
##    }
##    if(!$tr[1]) echo get_colspan($i,$cols);
##
function get_tr_tag($i$cols=5)
{
  
$tr[0] = ($i $cols) ? '' '<TR>';
  
$tr[1] = (++$i $cols) ? '' '</TR>';

  return 
$tr;
}

function 
get_colspan($i$cols=5$contents='&nbsp;')
{
  return 
'<TD colspan='. ($cols-$i%$cols) . ">$contents</TD></TR>\n";
}

## reference : http://jsboard.kldp.org/
##
function unhtmlspecialchars($str)
{
  
$tr array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  
$str preg_replace(array('/&#039;/','/&amp;/','/&(nbsp;|#032)/'),array("'",'&',' '),$str);
  
$str strtr($str,$tr);

  return 
$str;
}

## reference : http://jsboard.kldp.org/
##
function delete_tag($text)
{
  static 
$src = array
  (
    
';\n;i',
    
';<html.*<body[^>]*>;i',
    
';</body.*</html>.*;i',
    
';</*(div|span|layer|body|html|head|meta|input|select|option|form)[^>]*>;i',
    
';<(style|script|title).*</\\1>;i',
    
';</*(script|style|title|xmp)>;i',
    
';<(\\?|%);i',
    
';(\\?|%)>;i',
    
'/(=[0-9]+%)&gt;/i',
    
';#\^--ENTER--\^#;i'
  
);
  static 
$tar = array('#^--ENTER--^#','','','','','','&lt;\\1','\\1&gt;','\\1>','\n');

  return 
chop(preg_replace($src,$tar,$text));
}

## check HTML TABLE TAG
##
## author  : san2(at)linuxchannel.net
## changes : 2002.11.19
##
## argument :
##    $str  string, check string
##
## return :
##    $errcode integer, error code
##    0  -> ok, or, NULL, empty string('')
##    1  -> fail, 'ugly HTML TAG'
##    2  -> fail, '<TABLE> start/end TAG error'
##    3  -> fail, 1 and 2
##    4  -> fail, 'TABLE, TH, TR, TD array(open/close) TAG error'
##    5  -> fail, 1 and 4
##    6  -> fail, 2 and 4
##    7  -> fail, 1 and 2 and 4
##
function check_htmltable($str)
{
  static 
$from = array
  (
    
';[\d]+;',    // [0-9]+ to ''
    
';<(/?)(TABLE|TH|TR|TD)[^>]*>;i'// to '<\\1\\2>'
    
';<TABLE>;i',    // to 1
    
';<TR>;i',    // to 2
    
';<TH>;i',    // to 3
    
';<TD>;i',    // to 4
    
';</TD>;i',    // to 94
    
';</TH>;i',    // to 93
    
';</TR>;i',    // to 92
    
';</TABLE>;i',    // to 91
    
';[\D]+;'    // [^0-9]+ to ''
  
);
  static 
$to = array('','<\\1\\2>',1,2,3,4,94,93,92,91,'');

  if(!
preg_match(';</?TABLE[^>]*>;i',$str)) return 0;

  
$check preg_replace($from,$to,$str);

  
//$debug = '_debugging:'.$check;
  //$subtag = preg_replace('/[19]+/','',$check);

  
if(strlen($check)%3$errcode 1
  if(!
preg_match('/^12(3|4).+9291$/',$check)) $errcode += 2;

  while(
preg_match('/([\d])9\1/',$check))
  { 
$check preg_replace('/([\d])9\1/','',$check); }

  if(
$check$errcode += 4;

  return 
$errcode $debug;
}

function 
check_iframe($str)
{
  if(!
preg_match(';</?iframe[^>]*>;i'$str)) return 0;

  
$from = array(';[@#]+;',';<iframe[^>]*>;i',';</iframe[^>]*>;i',';[^@#];','@#');
  
$to = array('','@','#','','');

  return 
preg_replace($from,$to,$str); // ok(null), error(#,@,@#,...)
}

function 
tag_a($str$link$target=''$winstatus='')
{
  if(
$winstatus)
  {
    
$winstatus str_replace("'","\'",$winstatus);
    
$status " onMouseOver=\"window.status='$winstatus'; return true;\"";
    
$status .= " onMouseOut=\"window.status=''; return true;\"";
    
$title " TITLE='$winstatus;'";
  }

  if(
$target$target "TARGET='$target'";

  return 
"<A HREF='$link${target}${status}${title}>$str</A>";
}

function 
get_imgwidth($file$maxw=350)
{  
  if(!
file_exists($file)) return;
  if(
$maxw <= 0$maxw 350;

  
$size getimagesize($file);

  if(
$size[0] > $maxw)
  {
    
$size['h'] = round($size[1]*$maxw/$size[0]);
    
$size['w'] = $maxw;
    
$size['s'] = 'WIDTH='.$size['w'].' HEIGHT='.$size['h'];
  } else
  {
    
$size['w'] = $size[0];
    
$size['h'] = $size[1];
    
$size['s'] = $size[3];
  }

  return 
$size;
}
  
function 
get_imgheight($file$maxh=200)
{
  if(!
file_exists($file)) return;
  if(
$maxh <= 0$maxh 200;

  
$size getimagesize($file);

  if(
$size[1] > $maxh)
  {
    
$size['w'] = round($size[0]*$maxh/$size[1]);
    
$size['h'] = $maxh;
    
$size['s'] = 'WIDTH='.$size['w'].' HEIGHT='.$size['h'];
  } else
  {
    
$size['w'] = $size[0];
    
$size['h'] = $size[1];
    
$size['s'] = $size[3];
  }
  
  return 
$size;
}

require_once 
'_lib/func.client.php';

?>