Aug 15 2007

Substring - PHP

sub string php

More about PHP substr() function >>>

You know substr()
function in php. The normal usage of this function is here:

Sytax: substr($str, $start, $length);

<?php echo substr(’hello
world’,7,3); ?>
// First parameter is the string, second is
the start index (first character of the string starts from 0) and third param
is the length of the substring

Output: orl .

If we not specified the length parameter (parameter 3),
returns the string from $start to the end of the string.

example:
<?php
echo substr(’hello world’,7); ?>

gives the output: orld

If the $start parameter is a negative number, the position
starts from end of the string. Example:

<?php
echo substr(’on the way to operating theatre’, -9) ?>

gives an output: g theatre

another example:

<?php
echo substr(’on the way to operating theatre’, -9,3) ?>

output: g t

If $length is negative, substr( ) counts back from the end of the string to
determine
where your substring ends:

eg: <?php
echo substr(’on the way to operating theatre’, 4,-3) ?>
output: he way to operating thea

another eg: <?php
echo substr(’on the way to operating theatre’, -9,-3) ?>

output: g thea

Thanks and Regards

Syth

TAGS:

1 Comments on this post

Trackbacks

  1. wow said:
    February 29th, 2008 at 9:04 am

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Advt on sajithmr.com
    Itslife Online
    Advt on sajithmr.com
    Advt on sajithmr.com

Recent Comments

  • Binny V A: Thanks for the post - love the picture ;-)
  • TheAnand: A lot of people are seeing errors with google video chat….is there any other software which has to be...
  • Alex: Wow, interresting analysis you have done! I’m trying to run GoogleVoiceAndVideoSetup on linux, using...
  • Mella Fitriansyah: Nice plugin, I will try to add this plugin in my blog…
  • Mella Fitriansyah: Nice Info, Sir i will reading your another post success for you

Recent Readers

JOIN MY COMMUNITY!

Recent Posts