English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

please explain it clearly.. and show me some examples..
will substring be very useful in writing a website??
or its juz an useless function..
thanks before..

2007-08-01 00:34:10 · 3 answers · asked by xXx 1 in Computers & Internet Programming & Design

3 answers

ok, substr() lets you get part of a string that you place into it. You to reference a starting point, and a lenght of the string you want to get. Say you want to display a paragraph, but only want to get 100 characters of it, it would be like this:
So you know, the very first character of a strings (its index) starts at 0, not =1.

$smallerParagraph = substr($paragraph, 0, 100);

So you know, the very first character of a strings (its index) starts at 0, not =1.

Say you want to get characters 50 thru 100 from a paragraph, it would be like this:

$smallParagraph = substr($paragraph, 49, 50);

49 is the starting point, 50 is the amount of characters you want returned.

2007-08-01 01:14:55 · answer #1 · answered by Big D 4 · 0 0

The substring function returns a part of a string.

It is not designed to be rocket science.
You give the function the string, the start position and the length.
It will return a string of the given length.

What use is it?
Well will you ever use the atan2() function?

Until you find you have a full name in a database like "John Smith" of which you need to display Surname, First name. Then you are right. It is just a useless function.

2007-08-01 08:13:49 · answer #2 · answered by AnalProgrammer 7 · 0 1

Substring are very helfpul in manipulating data. It returns any part of string. For example:

echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f

// Accessing single characters in a string
// can also be achived using "curly braces"
$string = 'abcdef';
echo $string{0}; // a
echo $string{3}; // d
echo $string{strlen($string)-1}; // f

?>

For detailed explanation, you can visit the source below:

2007-08-01 08:15:00 · answer #3 · answered by ravelin101 2 · 0 1

fedest.com, questions and answers