ASP转PHP程序 v1.0案例

ASP转PHP程序 v1.0案例
ASP部分:
 

<% 
'作者:云祥孙 QQ313801120  http://sharembweb.com/
'循环类
Class whileclass
    Function myfun(nNumb)
        If nNumb = 1 Then
            Response.Write("hello world<hr>") 
        Else
            Response.Write("no numb<hr>") 
        End If 
    End Function 
    Sub nfor(n)
        Dim i 
        For i = 1 To n
            Response.Write(i & "for、<hr>") 
        Next 
    End Sub 
    Sub nwhile(n)
        While n > 1
            n = n - 1 
            Response.Write(n & "while、<hr>") 
        Wend 
    End Sub 
    Sub ndoloop(n)
        Do While n > 1
            n = n - 1 
            Response.Write(n & "doloop、<hr>") 
        Loop 
    End Sub 
    Sub nforeach()
        Dim splStr, s 
        splStr = Array("aa", "bb", "cc") 
        For Each s In splStr
            Response.Write("s=" & s & "<hr>") 
        Next 
    End Sub 
End Class 

'判断类
Class ifclass
    Function testif(n)
        If n > 10 Then
            Response.Write("n大于10<br>") 
        ElseIf n > 5 Then
            Response.Write("n大于5<br>") 
        Else
            Response.Write("n为默认<br>" & n) 
        End If 
    End Function 
    Function testif2(a)
        Response.Write("testif2<hr>") 
    End Function 


End Class 

'字典类
Class zdclass
    Sub testzd()
        Dim aspD, title, items, i 
        Dim aA, bB : Set aspD = Server.CreateObject("Scripting.Dictionary")
            aspD.add "Abs", "返回数字的绝对值11111111" 
            aspD.add "Sqr", "返回数值表达式的平方根aaaaaaaaaaaaaaaaaaaaaaaa" 
            aspD.add "Sgn", "返回表示数字符号的整数22222222" 
            aspD.add "Rnd", "返回一个随机生成的数字33333333333333" 
            aspD.add "Log", "返回指定数值的自然对数ssssssssssssssss" 


            Response.Write("Abs=" & aspD("Abs") & "<hr>") 
            Response.Write("Rnd=" & aspD("Rnd") & "<hr>") 
    End Sub
End Class 

'测试循环
Sub testwhile()
    Dim obj : Set obj = new whileclass
        Call obj.myfun(1) 
        Response.Write("<br>33333333<br>") 
        Call obj.myfun(2) 
        Call obj.nfor(6) 
        Call obj.nwhile(6) 
        Call obj.ndoloop(6) 
        Call obj.nforeach() 

End Sub
'测试判断
Sub testif()
    Dim obj : Set obj = new ifclass
        Call obj.testif(11) 
        Call obj.testif(6) 
        Call obj.testif(3) 
        obj.testif2 3 : obj.testif2 3 
End Sub
'测试字典
Sub testzd()
    Dim obj : Set obj = new zdclass
        Call obj.testzd() 

End Sub



'截取字符串 更新20160114
'c=[A]sharembweb.com[/A]
'0=sharembweb.com
'1=[A]sharembweb.com[/A]
'3=[A]sharembweb.com
'4=sharembweb.com[/A]
Function strCutTest(ByVal content, ByVal startStr, ByVal endStr, ByVal cutType)
    'On Error Resume Next
    Dim s1, s1Str, s2, s3, c 
    If InStr(content, startStr) = False Or InStr(content, endStr) = False Then
        c = "" 
        Exit Function 
    End If 
    Select Case cutType
        '完善于20150923
        Case 1
            s1 = InStr(content, startStr) 
            s1Str = Mid(content, s1 + Len(startStr)) 
            s2 = s1 + InStr(s1Str, endStr) + Len(startStr) + Len(endStr) - 1 '为什么要减1

        Case Else
            s1 = InStr(content, startStr) + Len(startStr) 
            s1Str = Mid(content, s1) 
            'S2 = InStr(S1, Content, EndStr)
            s2 = s1 + InStr(s1Str, endStr) - 1 
        'call echo("s2",s2)
    End Select
    s3 = s2 - s1 
    If s3 >= 0 Then
        c = Mid(content, s1, s3) 
    Else
        c = "" 
    End If 
    If cutType = 3 Then
        c = startStr & c 
    End If 
    If cutType = 4 Then
        c = c & endStr 
    End If 
    strCutTest = c 
    'If Err.Number <> 0 Then Call eerr(startStr, content)
'doError Err.Description, "strCutTest 截取字符串 函数出错,StartStr=" & EchoHTML(StartStr) & "<hr>EndStr=" & EchoHTML(EndStr)
End Function
 
'测试实例
sub testcase()

	Dim c 
	c = "[A]sharembweb.com[/A]" 
	
	Response.Write("c=" & c & "<br>") 
	
	Response.Write("0=" & strCutTest(c, "[A]", "[/A]", 0) & "<br>" & vbCrLf) 
	Response.Write("1=" & strCutTest(c, "[A]", "[/A]", 1) & "<br>" & vbCrLf) 
	'response.Write("2=" & strCutTest(c,"[A]","[/A]",2) & "<br>" & vbcrlf)
	Response.Write("3=" & strCutTest(c, "[A]", "[/A]", 3) & "<br>" & vbCrLf) 
	Response.Write("4=" & strCutTest(c, "[A]", "[/A]", 4) & "<br>" & vbCrLf) 

end sub


'选择
Select Case Request("act")
    Case "testwhile" : testwhile()                                        '测试循环
    Case "testif" : testif()                                              '测试判断
    Case "testzd" : testzd()                                              '测试字典
    Case "testcase" : testcase()                                              '测试实例
	

    Case Else : displayDefault()                                          '显示默认
End Select

'显示默认
Sub displayDefault()
    Response.Write("<a href='?act=testwhile'>测试循环</a> <br>") 
    Response.Write("<a href='?act=testif'>测试判断</a> <br>") 
    Response.Write("<a href='?act=testzd'>测试字典</a> <br>") 
    Response.Write("<a href='?act=testcase'>测试实例</a> <br>") 
End Sub  
%>  





PHP部分:

<?PHP
//作者:云祥孙 QQ313801120  http://sharembweb.com/
//循环类
class whileclass{
    function myfun($nNumb){
        if( $nNumb == 1 ){
            echo('hello world<hr>') ;
        }else{
            echo('no numb<hr>') ;
        }
    }
    function nfor($n){
        $i ='';
        for( $i = 1 ; $i<= $n; $i++){
            echo($i . 'for、<hr>') ;
        }
    }
    function nwhile($n){
        while( $n > 1){
            $n = $n - 1 ;
            echo($n . 'while、<hr>') ;
        }
    }
    function ndoloop($n){
        while( $n > 1){
            $n = $n - 1 ;
            echo($n . 'doloop、<hr>') ;
        }
    }
    function nforeach(){
        $splStr=''; $s ='';
        $splStr = array('aa', 'bb', 'cc') ;
        foreach( $splStr as $s){
            echo('s=' . $s . '<hr>') ;
        }
    }
}

//判断类
class ifclass{
    function testif($n){
        if( $n > 10 ){
            echo('n大于10<br>') ;
        }else if( $n > 5 ){
            echo('n大于5<br>') ;
        }else{
            echo('n为默认<br>' . $n) ;
        }
    }
    function testif2($a){
        echo('testif2<hr>') ;
    }


}

//字典类
class zdclass{
    function testzd(){
        $aspD=''; $title=''; $items=''; $i ='';
        $aA=''; $bB =''; $aspD=array(
        'Abs'=> '返回数字的绝对值11111111' ,
        'Sqr'=> '返回数值表达式的平方根aaaaaaaaaaaaaaaaaaaaaaaa' ,
        'Sgn'=> '返回表示数字符号的整数22222222' ,
        'Rnd'=> '返回一个随机生成的数字33333333333333' ,
        'Log'=> '返回指定数值的自然对数ssssssssssssssss' ,
        );

        echo('Abs=' . $aspD['Abs'] . '<hr>') ;
        echo('Rnd=' . $aspD['Rnd'] . '<hr>') ;
    }
}

//测试循环
function testwhile(){
    $obj =''; $obj = new whileclass();
    $obj->myfun(1) ;
    echo('<br>33333333<br>') ;
    $obj->myfun(2) ;
    $obj->nfor(6) ;
    $obj->nwhile(6) ;
    $obj->ndoloop(6) ;
    $obj->nforeach() ;

}
//测试判断
function testif(){
    $obj =''; $obj = new ifclass();
    $obj->testif(11) ;
    $obj->testif(6) ;
    $obj->testif(3) ;
    $obj->testif2( 3 ); $obj->testif2( 3 );
}
//测试字典
function testzd(){
    $obj =''; $obj = new zdclass();
    $obj->testzd() ;

}



//截取字符串 更新20160114
//c=[A]sharembweb.com[/A]
//0=sharembweb.com
//1=[A]sharembweb.com[/A]
//3=[A]sharembweb.com
//4=sharembweb.com[/A]
function strCutTest( $content, $startStr, $endStr, $cutType){
    //On Error Resume Next
    $s1=''; $s1Str=''; $s2=''; $s3=''; $c ='';
    if( instr($content, $startStr) == false || instr($content, $endStr) == false ){
        $c = '' ;
        return '';
    }
    switch ( $cutType ){
        //完善于20150923
        case 1;
        $s1 = instr($content, $startStr) ;
        $s1Str = mid($content, $s1 + strlen($startStr),-1) ;
        $s2 = $s1 + instr($s1Str, $endStr) + strlen($startStr) + strlen($endStr) - 1 ;//为什么要减1
        break;
        default;
        $s1 = instr($content, $startStr) + strlen($startStr) ;
        $s1Str = mid($content, $s1,-1) ;
        //S2 = InStr(S1, Content, EndStr)
        $s2 = $s1 + instr($s1Str, $endStr) - 1 ;
        //call echo("s2",s2)
    }
    $s3 = $s2 - $s1 ;
    if( $s3 >= 0 ){
        $c = mid($content, $s1, $s3) ;
    }else{
        $c = '' ;
    }
    if( $cutType == 3 ){
        $c = $startStr . $c ;
    }
    if( $cutType == 4 ){
        $c = $c . $endStr ;
    }
    $strCutTest = $c ;


    return @$strCutTest;
}

//测试实例
function testcase(){

    $c ='';
    $c = '[A]sharembweb.com[/A]' ;

    echo('c=' . $c . '<br>') ;

    echo('0=' . strCutTest($c, '[A]', '[/A]', 0) . '<br>' . vbCrlf()) ;
    echo('1=' . strCutTest($c, '[A]', '[/A]', 1) . '<br>' . vbCrlf()) ;
    //response.Write("2=" & strCutTest(c,"[A]","[/A]",2) & "<br>" & vbcrlf)
    echo('3=' . strCutTest($c, '[A]', '[/A]', 3) . '<br>' . vbCrlf()) ;
    echo('4=' . strCutTest($c, '[A]', '[/A]', 4) . '<br>' . vbCrlf()) ;

}


//选择
switch ( @$_REQUEST['act'] ){
    case 'testwhile' ; testwhile() ;break;//测试循环
    case 'testif' ; testif() ;break;//测试判断
    case 'testzd' ; testzd() ;break;//测试字典
    case 'testcase' ; testcase() ;//测试实例

    break;
    default ; displayDefault() ;//显示默认
}




//显示默认
function displayDefault(){
    echo('<a href=\'?act=testwhile\'>测试循环</a> <br>') ;
    echo('<a href=\'?act=testif\'>测试判断</a> <br>') ;
    echo('<a href=\'?act=testzd\'>测试字典</a> <br>') ;
    echo('<a href=\'?act=testcase\'>测试实例</a> <br>') ;
}
//系统函数列表
header("Content-Type: text/html; charset=gb2312");
function Rnd(){
	return (float)("0.".rand(1000000,9999999));
}
function InStr($content,$search){
	 
	if(is_array($content)){
 
		$content=arrayToString($content,"");
	
	} 
	
	if( $search!=""){
		if(strstr($content,$search)){
			return strpos($content,$search)+1;
		}else{
			return 0;
		}
	}else{
		return 0;
	}
}
function Mid($content,$nStart,$nLength=-1){
	$nStart--;				//可以从1开始
	if($nLength==-1){
		$nLength=strlen ( $content );
	}else{
		//$nLength--;
	} 
	return substr($content, $nStart, $nLength) ;
}
function Len($content){
	return strlen($content);				//采用这种
	//return strlen($content);
	//	return mb_strlen($content,'gb2312');
	$split = 1;	
	$n = 0;
	$array = array ();
	//echo (strlen ( $content ) . "<hr>");
	for($i = 0; $i < strlen ( $content );) {
		$value = ord ( $content [$i] );
		if ($value > 127) {
			if ($value >= 192 && $value <= 223)
				$split = 2;
			elseif ($value >= 224 && $value <= 239)
				$split = 3;
			elseif ($value >= 240 && $value <= 247)
				$split = 4;
		} else {
			$split = 1;
		}
		$key = NULL;
		for($j = 0; $j < $split; $j ++, $i ++) {
			$key .= $content [$i];
			$n ++;
		} 
		array_push ( $array, $key );
	} 
	return Count ( $array );
}
function vbCrlf(){
	return chr(13) . chr(10);
}
function Request($name){
	return @$_REQUEST[$name];
}

?>



友情链接