Thursday, July 12, 2012

PHP: substring

Use substr method:

$myString = "0123456789"
// substr( string_wanna_substring , initial position(0-index),quantity-of-digits-wanna-take);             
// the var is $myString, the init position is 3 (0-index) so it beings from number 3, take 3 chars beginning with 3 so the //final result is 345
$mySubString = substr( $myString ,3,3); // 345


Reference:
http://php.net/manual/es/function.substr.php

No comments: