2012년 7월 3일 화요일

asp vs php 비교

 

 













































































































































































ASP (VBScript)



PHP (v4.3+)


General syntax
ASP Comments, inline
'my dog has fleas
PHP Comments, inline
//my dog has fleas
ASP Comments, block

not available?
PHP Comments, block
/*
The quick brown fox
jumped over the lazy dogs.
*/
ASP, Escaping quotes
"""var text1=""<img src=\""blank.gif\"">"";"

PHP, Escaping quotes
\" or use ' like javascript'var text1="<img src=\"blank.gif\">";';

ASP Command termination
None, but : can be used to separate commands
on the same line.
PHP Command termination
Each command must end with ; but
multiple commands per line are allowed.
ASP Screen output
response.write "hello"
PHP Screen output
echo "hello";
ASP Newline characters
vbCrLfresponse.write "hello" & vbCrLf

PHP Newline characters
"\n" (must be inside "", not '')echo "hello \n";

ASP Variable Names
Not case sensitive,
so fName is the same as FNAME
PHP Variable Names
Case sensitive AND must begin with $
so $fName is NOT the same as $FNAME
String Functions
ASP String concatenation
&fname=name1 & " " & name2
emsg=emsg & "error!"

PHP String concatenation
. and .=$fname=$name1." ".$name2;
$emsg.="error!";

ASP, Change case
LCase(), UCase()lowerName=LCase(chatName)
upperName=UCase(chatName)

PHP, Change case
strtolower(), strtoupper()$lowerName=strtolower($chatName);
$upperName=strtoupper($chatName);

ASP String length
Len()n=Len(chatName)

PHP String length
strlen()$n=strlen($chatName);

ASP, Trim whitespace
Trim()temp=Trim(xpage)

PHP, Trim whitespace
trim() and also ltrim(), rtrim()$temp=trim($xpage);

ASP String sections

Left(), Right(), Mid()Left("abcdef",3)      result = "abc"Right("abcdef",2)     result = "ef"Mid("abcdef",3)       result = "cdef"Mid("abcdef",2,4)     result = "bcde"

PHP String sections

substr()substr("abcdef",0,3);     result = "abc"substr("abcdef",-2);      result = "ef"substr("abcdef",2);       result = "cdef"substr("abcdef",1,4);     result = "bcde"

ASP String search forward, reverse

Instr(), InstrRev()x=Instr("abcdef","de")        x=4x=InstrRev("alabama","a")     x=7

PHP String search forward, reverse

strpos(), strrpos()$x=strpos("abcdef","de");      x=3$x=strrpos("alabama","a");     x=6

ASP String replace
Replace(string exp,search,replace)temp=Replace(temp,"orange","apple")
temp=Replace(temp,"'","\'")
temp=Replace(temp,"""","\""")

PHP String replace
str_replace(search,replace,string exp)$temp=str_replace("orange","apple",$temp); $temp=str_replace("'","\\'",$temp);
$temp=str_replace("\"","\\\"",$temp);

ASP, split a string into an array

Split()temp="cows,horses,chickens"farm=Split(temp,",",-1,1)x=farm(0)

PHP, split a string into an array

explode()$temp="cows,horses,chickens";$farm=explode(",",$temp);$x=$farm[0];

ASP, convert ASCII to String
x=Chr(65) x="A"
PHP, convert ASCII to String
$x=chr(65); x="A"
ASP, convert String to ASCII
x=Asc("A") x=65
PHP, convert String to ASCII
$x=ord("A") x=65
Control Structures
ASP, if statements

if x=100 then  x=x+5elseif x<200 then  x=x+2else  x=x+1end if

PHP, if statements

if ($x==100) {  $x=$x+5;}else if ($x<200) {  $x=$x+2;}else {  $x++;}

ASP, for loops

for x=0 to 100 step 2  if x>p then exit fornext

PHP, for loops

for ($x=0; $x<=100; $x+=2) {  if ($x>$p) {break;}}

ASP, while loops

do while x<100  x=x+1  if x>p then exit doloop

PHP, while loops

while ($x<100) {  $x++;  if ($x>$p) {break;}}

ASP, branching

select case chartName  case "TopSales"    theTitle="Best Sellers"    theClass="S"  case "TopSingles"    theTitle="Singles Chart"    theClass="S"  case "TopAlbums"    theTitle="Album Chart"    theClass="A"  case else    theTitle="Not Found"end select

PHP, branching

switch ($chartName) {  case "TopSales":    $theTitle="Best Sellers"; $theClass="S";    break;  case "TopSingles":    $theTitle="Singles Chart"; $theClass="S";    break;  case "TopAlbums":    $theTitle="Album Chart"; $theClass="A";    break;  default:    $theTitle="Not Found";}

ASP functions

Function myFunction(x)  myFunction = x*16  'Return valueEnd Function

PHP functions

function myFunction($x) {  return $x*16;  //Return value}

HTTP Environment
ASP, Server variables

Request.ServerVariables("SERVER_NAME")Request.ServerVariables("SCRIPT_NAME")Request.ServerVariables("HTTP_USER_AGENT")Request.ServerVariables("REMOTE_ADDR")Request.ServerVariables("HTTP_REFERER")

PHP, Server variables

$_SERVER["HTTP_HOST"];$_SERVER["PHP_SELF"];$_SERVER["HTTP_USER_AGENT"];$_SERVER["REMOTE_ADDR"];@$_SERVER["HTTP_REFERER"];     @ = ignore errors

ASP Page redirects
Response.redirect("wrong_link.htm")
PHP Page redirects
header("Location: wrong_link.htm");
ASP, GET and POST variables
Request.QueryString("chat")
Request.Form("username")
PHP, GET and POST variables
@$_GET["chat"];       @ = ignore errors
@$_POST["username"];
ASP, prevent page caching
Response.CacheControl="no-cache"
Response.AddHeader "pragma","no-cache"
PHP, prevent page caching
header("Cache-Control: no-store, no-cache");
header("Pragma: no-cache");
ASP, Limit script execution time, in seconds
Server.ScriptTimeout(240)
PHP, Limit script execution time, in seconds
set_time_limit(240);
ASP, Timing script execution

s_t=timer ...ASP script to be timed...duration=timer-s_tresponse.write duration &" seconds"

PHP, Timing script execution

$s_t=microtime();...PHP script to be timed...$duration=microtime_diff($s_t,microtime());$duration=sprintf("%0.3f",$duration);echo $duration." seconds";//required functionfunction microtime_diff($a,$b) {  list($a_dec,$a_sec)=explode(" ",$a);  list($b_dec,$b_sec)=explode(" ",$b);  return $b_sec-$a_sec+$b_dec-$a_dec;}

File System Functions
ASP, create a file system object (second line is wrapped)
'Required for all file system functions
fileObj=Server.CreateObject
("Scripting.FileSystemObject")
PHP, create a file system object
Not necessary in PHP
ASP, check if a file exists
pFile="data.txt"
fileObj.FileExists(Server.MapPath(pFile))
PHP, check if a file exists
$pFile="data.txt";
file_exists($pFile);
ASP, Read a text file

pFile="data.txt"xPage=fileObj.GetFile(Server.MapPath(pFile))xSize=xPage.Size  'Get size of file in bytesxPage=fileObj.OpenTextFile(Server.MapPath(pFile))temp=xPage.Read(xSize)  'Read filelinkPage.Close

PHP, Read a text file

$pFile="data.txt";$temp=file_get_contents($pFile);  //Read file

Time and Date Functions
ASP, Server Time or Date
Now, Date, Time
PHP, Server Time or Date
date()
ASP, Date format (default)
Now = 7/2/2012 4:21:51 AM
Date = 7/2/2012
Time = 4:21:51 AM
Various ASP functions extract date parts:

Month(Date) = 7
MonthName(Month(Date)) = July
Day(Date) = 2
WeekdayName(Weekday(Date)) = Monday
WeekdayName(Weekday(Date),False) = Mon

PHP, Date format
There is no default format in PHP.
The date() function is formatted using codes:
date("n/j/Y g:i:s A") = 7/2/2012 4:21:51 AM

date("n") = 7
date("F") = July
date("j") = 2
date("l") = Monday
date("D") = Mon

Numeric Functions
ASP, convert decimal to integer
Int()n=Int(x)

PHP, convert decimal to integer
floor()$n=floor($x);

ASP, determine if a value is numeric
IsNumeric()if IsNumeric(n) then ...

PHP, determine if a value is numeric
is_numeric()if (is_numeric($num)) {...}

ASP, modulus function
x mod y
PHP, modulus function
$x % $y

 

http://www.design215.com/toolbox/asp.php

 

 

2012년 6월 28일 목요일

ssh 프로세스 우선순위 높이기

가끔 서버의 접속이 안되는 경우가 있다.

메모리 부족으로 스왑을 사용하는 경우 매우 느려져, 결국은 재부팅을 할 수 밖에 없는 상황이 온다.

이럴때 ssh 만 접속 된다면 해당 프로세스를 죽여서 재부팅이 필요하지 않을 듯 하다.

 

~/.ssh/rc 파일을 만들고 이렇게 넣어준다.
ps -o pid -C sshd --no-heading | xargs renice 19 > /dev/null

 

rc 파일이 뭐냐면 ssh 접속하면 해당 내용을 실행하는 파일이다.

ssh의 우선순위를 최고로 변경.

http://www.davidgrant.ca/starting_sshd_with_a_higher_nice_value
ps. 문제 발생. ssh 를 이용한 rsync 동기화시

rsync : protocol version mismatch -- is your shell clean? 에러 발생

주석처리하고 /etc/profile에 넣음.

원 글에서는 cron에 넣으라고 나온다. /etc/profile도 문제 발생하면 그냥 cron에 등록...

 

 

 

 

 

 

 

2012년 6월 15일 금요일

windows XP 이상에서 특정 포트 사용 프로세스 확인 command

windows XP 이상에서 특정 포트 사용 프로세스 확인 command

==========================================
netstat -naob

==========================================

; 1234 사용 포트 PID 확인
C:\>netstat -ano | find "1234"

TCP 0.0.0:4899 0.0.0.0:0 LISTENING 567

; 567 PID 프로세스명 확인
C:\>tasklist /FI "PID eq 567"
이미지 이름 PID 세션 이름 세션# 메모리 사용
=========== === ========= ===== ===========
process.exe 567 Console  0 4,700 K

※ windows 2000 server에서는 tlist 명령 사용

; 1234 포트 사용 프로세스 kill
C:\> for /f "tokens=5" %p in (' netstat -ano ^| find ":1234" ') do taskkill /F /PID %p

; 1234 포트 사용 프로세스 확인
C:\> for /f "tokens=5" %p in (' netstat -ano ^| find ":1234" ') do tasklist /FI "PID eq %p"

2012년 6월 5일 화요일

마이피플 API 로 메세지 보내기

마이피플의 API 를 통해 웹에서 메시지를 전송가능 하단걸 알았다.

라인은 API 가 없는 거 같고, 카톡은 일반 웹에서는 안되고, 모바일 웹에서만 된다는 점에서 일반웹에서는 사용할 수 없다.

마이피플도 정상적인 API가 아니라 마이피플 위젯을 이용한 꼼수(?)라고 봐야 될 거 같다.

만들려고 보니 이미 만드신 분이 있었다. 역시~

http://www.phpwork.kr/Downloads/viewDownloadDetail/0/1/33

자체 개발 하신 Spac 프레임워크 란 걸 사용 해야 하는 단점이 있다.

해당 프레임 워크 를 사용 안해도 된다고 하셨는데, 그럼 오류 난다.

소소는 아래와 같은데,  아래 처럼 바꿔서 사용 가능 하다.

보니까 워낙 간단한 내용이라서, 함수로 만들어서 사용하는 게 나을 듯 하다.

귀찮아서 그냥 씀.


ps. 위젯 서비스가 종료... 안됨..

jquery sortable 사용법


<script type="text/javascript">$(document).ready(function() {    $("#table_sortable tbody.content").sortable({      update: function() {    $('input[name="members[]"]').each( function(index,elem) { //인덱스       $('#table_sortable tbody.content tr:eq('+ index  +') td input:eq(3)').val(index); //타겟        });   }  });});</script>


테이블단위의 sortable은 위와 같이 tbody를 사용한다.

update: 는 이동 완료했을 시 시작.

위의 코드는 테이블을 이동했을 시, members[] 를 읽어들어가며 타겟의 값을 index 값으로 순서대로 변경 해주는 코드

순서를 옮기면 타겟값에 무조건 위에서 부터 0,1,2,3,4,5 이렇게 들어감.




최신 버젼에서는 안됨.


2012년 6월 4일 월요일

웹표준 플래시 삽입

            <object type="application/x-shockwave-flash" data="파일경로" width="980" height="95" > 			<param value="파일경로" name="movie" />			<param value="high" name="quality" />			<param value="transparent" name="wmode" />			<param value="  " name="flashVars" />			<param value="always" name="allowScriptAccess" />            </object>


웹표준 플래시 삽입


출처:http://blog.daum.net/_blog/BlogTypeView.do?blogid=05mzE&articleno=16157018#ajax_history_home

2012년 5월 26일 토요일

속성 셀렉터 표현

jquery 의 속성 셀렉터 사용시

$('a[ref=nofollow self]') 의 책에서 표현식이 사용가능 하다고 나와 있는 데, 최신 버젼이라서 그런지 안됨.

$('a[ref="nofollow self"]') 이런식으로 큰 따옴표와 작은 따옴표를 섞어 쓰던지

$('a[ref=\'nofollow self\']') 역슬래시로 처리 해줘야 됨.