There is a Substring method as a function to cut out a specified part of a character string. There is also a charAt method. Cut out an arbitrary length of the character string starting from the specified position.
public String substring(int Index)
public String substring(int startIndex, int endIndex)
Java's subString method has the above two usages. There are the following usages.
String s1 = "Hello World";
// o World
s1.subString(4)
// O World
s1.subString(4, 11);
string substr (String $string, int $start [,int $length ] )
string Input string. At least one character must be specified.
start If start is positive, the returned string is a string starting from the start, counting from 0 in String. If start is negative, the returned string is the string starting from the start, counting from the end of the String.
length If length is positive, the returned string will be the number of characters in length counting from start. If length is negative, the character for that string is omitted from the end of string.
<?php
$rest = substr("Hello World", -1); // "d"return it
$rest = substr("v", -2); // "ld"return it
$rest = substr("Hello World", -3, 1); // "r"return it
?>
I use Java for business, so I understand it to some extent, but I've never heard of PHP's substr method. Therefore, I wrote it in detail.
Recommended Posts