PHP learning every day(2)

parse_url — Parse a URL and return its components


(PHP 4, PHP

ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address

(PHP 4, PHP 5)

list — Assign variables as if they were an array

<?php

$info 
= array('coffee''brown''caffeine');

// Listing all the variables
list($drink$color$power) = $info;
echo 
"$drink is $color and $power makes it special.\n";

// Listing some of them
list($drink, , $power) = $info;
echo 
"$drink has $power.\n";

// Or let's skip to only the third one
list( , , $power) = $info;
echo 
"I need $power!\n";

// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL
?>


(PHP 4, PHP 5)

explode — Split a string by string

array explode    ( string $delimiter   , string $string   [, int $limit  ] )

Returns an array of strings, each of which is a substring of   string formed by splitting it on   boundaries formed by the string delimiter.

Returns an array of strings   created by splitting the string parameter on   boundaries formed by the delimiter.

If delimiter is an empty string (""),   explode() will return FALSE.   If delimiter contains a value that is not   contained in string and a negative   limit is used, then an empty array will be   returned, otherwise an array containing   string will be returned.

?php
// Example 1
$pizza  "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces explode(" "$pizza);
echo 
$pieces[0]; // piece1
echo $pieces[1]; // piece2

// Example 2
$data "foo:*:1023:1000::/home/foo:/bin/sh";
list(
$user$pass$uid$gid$gecos$home$shell) = explode(":"$data);
echo 
$user// foo
echo $pass// *

?>


str_replace — Replace all occurrences of the search string with the replacement string

mixed str_replace    ( mixed $search   , mixed $replace   , mixed $subject   [, int &$count  ] )

This function returns a string or an array with all occurrences of   search in subject   replaced with the given replace value.

If you don't need fancy replacing rules (like regular expressions), you   should always use this function instead of preg_replace().

This function returns a string or an array with the replaced values. 


Using PDO to communicates with MySQL

/***********Make an Connection*******************/

$dbh = new PDO("mysql:dbname=".$dbname.";host=".$db_host", $dbuser, $dbpasswd);

/**********Close A connection**********************/

$dbh = null;

/**************Exception****************/

PDOException $e

    $e->getMeesage();


After create a connection, we can execute the SQL commands using the connection

PDOStatement::fetch();// retrieve a row of the data from the database.

PDOStatement::fetchAll();// retrieve multiple rows of the data from the database

PDOStatement::execute() // Be used to execute the INSERT, UPDATE, DELETE query commands that don't return results.

PDOStatement::prepare();// prepare an SQL query to be executed


转载于:https://my.oschina.net/vihcle/blog/300563

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值