Substring to take all letters after the 4th character

I only have a basic understanding of substring. I am trying to extract the first 4 characters as a string variable and extract the rest of the characters into another string variable. How can I do this using a substring? With PHP

$rest = substr("jKsuSportTopics", -3, 1);
$rest2 = substr("jKsuSportTopics", 4, 0);

      

+3


source to share


1 answer


The second argument is the starting index and the third argument is the length of the string. If the third argument is missing, you get the rest of the string.

$first_part = substr("jKsuSportTopics", 0, 4);
$rest = substr("jKsuSportTopics", 4);

      



Here's a quote from the docs :

... the returned string will start at start

'th position in string

, counting from zero. For example, in the string "abcdef" the character at position 0 is "a", the character at position 2 is "c", and so on.

[...]

If length

given and positive, the returned string will contain no more than length

characters starting with start

(depending on the length of the string).

[...]

If length

omitted, substring starting with start

, until the end of the string is returned.

+5


source







All Articles