PHP 与 Perl 对照表
生活随笔
收集整理的這篇文章主要介紹了
PHP 与 Perl 对照表
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
| @a = ();@a = ( 'xx', 11, 33.5, );@a = 12..33;$a[2] = 'something';$len = scalar(@a); # or $len = @a;@a3 = ('xx', @a1, @a2);($x, $y) = @a;$a[@a] = 'new'; # pushpush pop shift unshift spliceforeach $i (@a) { .. } | $a = array();$a = array( 'xx', 11, 33.5, );$a = range(12,33);$a[2] = 'something';$len = count($a);$a3 = array_merge('xx', $a1, $a2);list($x, $y) = $a;$a[] = 'new'; # pusharray_push array_pop array_shift array_unshift array_spliceforeach ($a as $i) { .. } |
| %h = ();%h = ( 'x' => 'y','z' => 'w',);$h{'x'} = 7;while (($key,$value) = each(%h)) { .. }$a = keys(%h); $b = values(%h);delete $h{'x'}; | $h = array();$h = array( 'x' => 'y','z' => 'w',);$h['x'] = 7;foreach ($h as $key => $value) { .. }$a = array_keys($h); $b = array_values($h);unset( $h['x'] ); |
| %h = ('a'=>13, 'b'=>25); @x = ('hi', 'there', 'all',);@mix = ( %h, @x,[33..39],{ x=>15, yy=>23, },);$mix[0]->{'b'} # == 25 $mix[0]{'b'} # == 25 $mix[2]->[2] # == 35 $mix[2][2] # == 35 | $h = array('a'=>13, 'b'=>25); $x = array('hi', 'there', 'all',);$mix = array($h, $x,range(33,39),array('x'=>15, 'yy'=>23),);$mix[0]['b'] # == 25$mix[2][2] # == 35 |
| @a = split( '|', $s );@a = split( 's+', $s );$s = join( '|', @a ); | $a = preg_split( '/|/', $s,-1, PREG_SPLIT_NO_EMPTY ); $a = preg_split( '/s+/', $s,-1, PREG_SPLIT_NO_EMPTY );$s = join( '|', $a ); |
| $s = lc($s); $s = uc($s);$s =~ tr/a-z/A-Z/; | $s = strtolower($s); $s = strtoupper($s); |
| $s1 eq $s2$s1 lt $s2 | strcmp($s1,$s2) == 0 # or $s1 === $s2strcmp($s1,$s2) < 0 |
| sub foo {my @args = @_; }sub foo {$x = 5; }foo2( @a, %h ); | function foo() {$args = func_get_args(); }function foo() {global $x;$x = 5; }function foo2($x, $y) { }foo2( $a, $h ); |
| $s =~ m/(w+)/; $substr = $1;@all = ($s =~ m/(w+)/g);$s =~ s/s+/X/; $s =~ s/s+/X/g;$s =~ s/^s+|s+$//g; | preg_match( "/(w+)/", $s, $match ); $substr = $match[1];preg_match_all( "/(w+)/", $s, $match ); $all = $match[0];$s = preg_replace( "/s+/", 'X', $s, 1 ); $s = preg_replace( "/s+/", 'X', $s );$s = trim($s); |
| use File::Basename;$b = basename($path); $d = dirname($path); | $b = basename($path); $d = dirname($path); |
| %ENV$ENV{REQUEST_METHOD}$ARGV[$i]$0 | $_SERVER$_SERVER[REQUEST_METHOD]$argv[$i+1]$argv[0] # Php/CGI only |
| #form/hyperlink parameters: # s : single-valued # m : multi-valueduse CGI (:standard);$s = param('s'); @m = param('m');@param_names = param(); $num_params = param(); | #form/hyperlink parameters: # s : single-valued # m[] : multi-valued # (such as multi-selections # and checkbox groups)$PARAM= array_merge($_GET, $_POST);$s = $PARAM['s']; # a scalar $m = $PARAM['m']; # an array$param_names = array_keys($PARAM); $num_params = count($PARAM); |
| use CGI (:standard);$ref = "x.cgi"; a({href=>$ref}, "yy")textfield({name=>"yy", size=>5})password({name=>"yy", size=>5})textarea({name=>"yy",cols=>5, rows=>2})submit({value=>"yy"})button( {name=>"xx",value=>"yy",οnclick=>"submit()",})%labels = (0=>'a',1=>'q',2=>'x'); popup_menu( { name=>"xx",values=>[0..2],labels=>%labels,size=>4,})@a = ('xx','yy','zz'); radio_group( { name=>'nn',values=> @a,default=>'_',linebreak=>1,})%labels = ('xx'=>'L1','yy'=>'L2'); @a = keys( %labels ); checkbox_group( { name=>'nn',values=> @a,labels=> %labels,})table(Tr([td(['a','b']),td(['x','y']),])) | # The Perl/CGI functions have the # additional property of "stability" # when used in reentrant forms. # The values of the HTML elements are # set according to the incoming # parameter values for those elements. # The versions below are not stable.$ref = "x.php"; <a href="<?php echo $ref?>">yy</a><input type=text name=yy size=5><input type=password name=yy size=5><textarea name=yy cols=5 rows=2></textarea><input type="submit" value=yy><input type="button"name="xx" value="yy"οnclick="submit()"><select name="xx" size="4"> <?php $labels = array(0=>'a',1=>'q',2=>'x'); foreach (range(0,2) as $_)echo "<option value='$_'>",$labels[$_]; ?></select>$a = array('xx','yy','zz'); foreach ($a as $_)echo "<input type=radioname=nn value='$_'>$_<br>";$labels = array('xx'=>'L1','yy'=>'L2'); foreach (array_keys($labels) as $_)echo "<input type=checkboxname=nn value='$_'>",$labels[$_];<table> <tr> <td>a</td><td>b</td></tr> <tr> <td>x</td><td>y</td> </tr> </table> |
| use URI::Escape;uri_escape($val) uri_unescape($val) | urlencode($val) urldecode($val) |
| use DBI; $dbh = DBI->connect('DBI:mysql:test:localhost',$usr,$pwd );$dbh->do( $sql_op )$query = $dbh->prepare( $sql_op ); $query->execute();while(@record = $query->fetchrow() ) { .. }$dbh->quote($val) | $dbh = mysql_connect('localhost', $usr, $pwd ); mysql_query('USE test')mysql_query( $sql_op );$results = mysql_query( $sql_op );while($record =mysql_fetch_row($results)) { .. }"'" . addslashes($val) . "'" |
總結(jié)
以上是生活随笔為你收集整理的PHP 与 Perl 对照表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 李想:很多公司在学习华为组织构造 但这一
- 下一篇: 跟爱奇艺学会了!网飞实施反密码共享新规定