php中substr的用法详解
php中substr的用法详解
php.net中关于substr的说明很简单:
start
If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.
If start is negative, the returned string will start at the start 'th character from the end of string .
length
If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string ). If string is less than or equal to start characters long, FALSE will be returned.
If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned.
下面,我详细总结一下关于substr的相关用法:
原型:string substr ( string $string , int $start [, int $length ] ),它可以用于在一个较长的字符串中查找匹配的字符串或字符。$string为所要处理的字符串,$start为开始选取的位置,$length为要选取的长度
例:
<?php
//此教程来源于97xxoo教程网([url=http://www.97xxoo.org]www.97xxoo.org[/url])
查看完整的教程请点:[url=http://www.97xxoo.org/article/1/2008/20081115345.shtml]http://www.97xxoo.org/article/1/2008/20081115345.shtml[/url]
$rest1 = substr("abcdef", 0, 0); // returns ""
$rest2 = substr("abcdef", 0, 2); // returns "ab"
$rest3 = substr("abcdef", 0, -1); // returns "abcde"
$rest4 = substr("abcdef", 2,0); // returns ""
$rest5 = substr("abcdef", 2,2); // returns "cd"
$rest6 = substr("abcdef", 2, -1); // returns "cde"
$rest7 = substr("abcdef", -2,0); // returns ""
$rest8 = substr("abcdef", -2,2); // returns "ef"
$rest9 = substr("abcdef", -2,-1); // returns "e"
?>
$start如果为非负数,在字符串中以0为开头从左向右开始记数,[url=http://www.caoliushequ8.cn]草榴社区[/url]即0代表字符"a",1则代�
相关文档:
<?php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
......
WebService简介
一. 概述
目前进行Web Service通信有两种协议标准,一种是XML-RPC,另外一种是SOAP。
1. XML-RPC比较简单,出现时间比较早;
2. SOAP比较复杂,主要是一些需要稳定、健壮、安全并且复杂交互的时候使用。
PHP中� ......
防止以后忘掉,贴在这儿啦
function GetWeekDate($week,$year)
{
$timestamp = mktime(0,0,0,1,1,$year);
$dayofweek = date("w",$timestamp);
if( $week != 1)
&nb ......
<?php
date_default_timezone_set("Etc/GMT-8");
header("content-type:text/html; charset=utf-8");
/**
* 自己定义的一个生成日历的类
* @author 张伟灿<yuanfen860913@163.com>
* @version 1.0.0
*
*/
class myCalendar
{
......