★ wanayoo — archive 1999 http://php.net/manual/it/function.substr.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Strings
Quick Reference
Strings
English version of this pageGerman version of this pageJapanese version of this page
Italian version of this pageFrench version of this pageHungarian version of this page
Spanish version of this page
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crc32
* crypt
* echo
* explode
* get_html_translation_table
* get_meta_tags
* hebrev
* hebrevc
* htmlentities
* htmlspecialchars
* implode
* join
* levenshtein
* ltrim
* md5
* Metaphone
* nl2br
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* quotemeta
* rtrim
* sscanf
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* stripcslashes
* stripslashes
* stristr
* strlen
* strnatcmp
* strnatcasecmp
* strncmp
* str_pad
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_count
* substr_replace
* trim
* ucfirst
* ucwords
* wordwrap

  Thanks to:
 Chek.com
 easyDNS
 VA Linux Systems

  Related sites:
Apache
MySQL
PostgreSQL
Zend Tech.

  Community:
LinuxFund.org
OSDN
Manual: substr
View the source code for this pageSearch the site



Previous page
 strtr
 Updated
Mon, 18 Sep 2000
substr_count 
Next page


substr

(PHP3 <= 3.0.16, PHP4 )

substr -- Return part of a string

Description

string substr (string string, int start [, int length])

Substr returns the portion of string specified by the start and length parameters.

If start is positive, 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.

Examples:


$rest = substr ("abcdef", 1);    // returns "bcdef"
$rest = substr ("abcdef", 1, 3); // returns "bcd"
      

If start is negative, the returned string will start at the start'th character from the end of string.

Examples:


$rest = substr ("abcdef", -1);    // returns "f"
$rest = substr ("abcdef", -2);    // returns "ef"
$rest = substr ("abcdef", -3, 1); // returns "d"
      

If length is given and is positive, the string returned will end length characters from start. If this would result in a string with negative length (because the start is past the end of the string), then the returned string will contain the single character at start.

If length is given and is negative, the string returned will end length characters from the end of string. If this would result in a string with negative length, then the returned string will contain the single character at start.

Examples:


$rest = substr ("abcdef", 1, -1); // returns "bcde"
      

See also strrchr() and ereg().


User Contributed Notes: substr


yzhang@sfu.ca
20-Jul-1999 12:18
If you want to do pad a string from the left (eg. from "8" to "0008"), you can use this:

$num = substring("0000".$num, -4, 4)



tim@sod.co.uk
20-Apr-2000 05:22
If you want to make it start at 1 you can add this simple code to any script:


$one=0;

substr("Hello",$one,5);



 About Notes


Previous page
 strtr
 Updated
Mon, 18 Sep 2000
substr_count 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.