'Programming'에 해당되는 글 38건
- 2008.11.17 PHP Convert HTML to text
- 2008.11.17 vb 서브폴더 구하기
- 2008.11.17 vb 이미지를 불러와 가로, 세로크기를 구한다.
- 2008.11.17 vb 복호화
- 2008.11.17 vb 암호화
- 2008.11.17 vb php의 ceil() 과 같은 기능을 한다.
- 2008.11.17 vb table tag안에 br을 제거한다.
- 2008.11.17 vb nl2br() 구현
- 2008.11.17 vb page번호 출력
- 2008.11.17 vb 페이지번호나 레코드번호 값을 받아 페이지리스트 출력
Example 1. Convert HTML to text
<?php
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array (\'@<script[^>]*?>.*?</script>@si\', // Strip out javascript
\'@<[\\/\\!]*?[^<>]*?>@si\', // Strip out HTML tags
\'@([\\r\\n])[\\s]+@\', // Strip out white space
\'@&(quot|#34);@i\', // Replace HTML entities
\'@&(amp|#38);@i\',
\'@&(lt|#60);@i\',
\'@&(gt|#62);@i\',
\'@&(nbsp|#160);@i\',
\'@&(iexcl|#161);@i\',
\'@&(cent|#162);@i\',
\'@&(pound|#163);@i\',
\'@&(copy|#169);@i\',
\'@&#(\\d+);@e\'); // evaluate as php
$replace = array (\'\',
\'\',
\'\\1\',
\'\"\',
\'&\',
\'<\',
\'>\',
\' \',
chr(161),
chr(162),
chr(163),
chr(169),
\'chr(\\1)\');
$text = preg_replace($search, $replace, $document);
' ---------------------------------------------
' 서브폴더 구하기(재귀호출)
' 함수사용전에 전역변수로 fso, path가 선언되 있어야 한다.
' strFld를 리턴한다.
' vb Script에서는 배열의 크기가 자동으로 증가되지 않기 때문에
' vbCrLf를 구분자로 사용해서 문자열로 리턴함.
' ---------------------------------------------
function getSubFolder(fso, path, strFld, depth)
Dim fld, sfld, f, fld1, sfld1, files
if not isObject(fso) then
getSubFolder = "fso가 선언되지 않았습니다."
Exit function
end if
set fld = fso.getfolder(path)
set sfld = fld.subfolders
for each f in sfld
set fld1 = fso.getfolder(f.path)
set files = fld1.files
set sfld1 = fld1.subfolders
if Len(strFld) > 0 then strFld = strFld & vbCrLf
strFld
= strFld & depth & "|" & f.name & "|" & f.path
& "|" & files.count & "|" & sfld1.count
if sfld1.count > 0 then Call getSubFolder(fso, f.path, strFld, depth+1)
next
getSubFolder = strFld
end function
' ---------------------------------------------------
' 이미지를 불러와 가로, 세로크기를 구한다.
' ---------------------------------------------------
function getImageSize(imgPath)
Dim pic, picWH(1)
' LoadPicture를 지원하지 않는 서버가 있는데..
' 이유는 모르겠다.
On Error Resume Next
set pic = LoadPicture(imgPath)
if Err.Number > 0 then
response.write err.number & ": " & err.description
picWH(0) = 500 ' set default value
picWh(1) = 500
getImageSize = picWH
exit function
end if
picWH(0) = CLng(CDbl(pic.Width) * 24 / 635)
picWH(1) = CLng(CDbl(pic.Height) * 24 / 635)
set pic = nothing
getImageSize = picWH
end function
' --------------------------------------------
' 복호화
' --------------------------------------------
function unEncrypt(theText)
Dim output, Temp(), Temp2()
'theText = unEscape(theText)
TextSize = Len(theText)
if TextSize < 1 then
unEncrypt = ""
exit function
end if
ReDim Temp(TextSize-1)
ReDim Temp2(TextSize-1)
for i = 0 to TextSize-2 step 2
Temp(i) = AscW(Mid(theText, i+1, 1))
Temp2(i) = AscW(Mid(theText, i+2, 1))
next
for i = 0 to TextSize-1 step 2
output = output & ChrW(Temp(i) - Temp2(i))
next
unEncrypt = output
end function
' -------------------------------------------- Randomize
' 암호화
' --------------------------------------------
function Encrypt(theText)
Dim output, Temp(), Temp2()
TextSize = Len(theText)
if TextSize < 1 then
Encrypt = ""
exit function
end if
ReDim Temp(TextSize-1)
ReDim Temp2(TextSize-1)
for i = 0 to TextSize-1
rndVal = Int((255 * Rnd) + 128)
' mid 는 자동으로 2바이트 문자를 1글자로 인식한다.
Temp(i) = AscW(Mid(theText, i+1, 1)) + rndVal
Temp2(i) = rndVal
next
for i = 0 to TextSize-1
output = output & ChrW(Temp(i)) & ChrW(Temp2(i))
next
'Encrypt = Escape(output)
Encrypt = output
end function
' ----------------------------------------------------------
' php의 ceil() 과 같은 기능을 한다.
' ----------------------------------------------------------
function ceil(num)
' 소수점이 있으면 1을 더한다.
if num - int(num) > 0 then
ceil = Int(num) + 1
else
ceil = Int(num)
end if
end function
' ---------------------------------------------------------- ' table안에 \n이 br로 치환되지 않도록 구분함.
' table tag안에 br을 제거한다.
' ----------------------------------------------------------
function conv_nl(str)
'str = stripslashes($str);
str = eregi_replace("<br>(\r\n|\n\r|\r|\n)", vbLf, str)
str = ereg_replace("(\r\n|\n\r|\r)", vbLf, str)
str = eregi_replace("<(/?(TABLE|TR|TH|TD)[^>]*)> *\n", "<$1>\t_nl_\t", str)
' table태그 앞에 공백을 없앤다.
str = eregi_replace(" *<(/?(TABLE|TR|TH|TD)+)", "<$1", str)
' <, > 태그 안에 \n 제거
str = ereg_replace("<([^><\n]*)\n+([^><\n]*)>", "<$1 $2>", str)
str = ereg_replace("\n[:space:]*\n", "<BR>" & vbLf, str)
str = ereg_replace("\n\n", "<BR><BR>" & vbLf, str)
str = nl2br(str)
str = ereg_replace("\t_nl_\t", vbLf, str)
str = eregi_replace("</?pre>", "", str)
conv_nl = str
end functio
' ----------------------------------------------------------
' nl2br() 구현
' ----------------------------------------------------------
function nl2br(str)
nl2br = ereg_replace("(\r\n|\n\r|\r|\n)", "<br>", str)
end function
' ----------------------------------------------------------
' page번호 출력
' ----------------------------------------------------------
function page_print(pi, page_per_block, get_param)
' 처음, 이전 출력
if pi(PiStart_page) > 1 then
pp = "<a href=" & get_param & "&page=1>[처음] </a>" & _
"<a href=" & get_param & "&page=" & pi(PiPre_page) & ">[이전 " & _
page_per_block & "개]</a> "
end if
' 페이지 번호 출력
for i = pi(piStart_page) to pi(piEnd_page)
if i = pi(piCurrent_page) then
pp = pp & "<font color='red'>[" & i & "]</font> "
else
pp = pp & "<a href=" & get_param & "&page=" & i & ">[" & i & "]</a> "
end if
next
' 다음, 끝 출력
if pi(piEnd_page) < pi(piTotal_page) then
pp
= pp & "<a href=" & get_param & "&page=" &
pi(piNext_page) & ">[다음 " & page_per_block &
"개]</a> " &_
"<a href=" & get_param & "&page=" & pi(piTotal_page) & ">[끝]</a> "
end if
page_print = pp
end function