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 in another string variable. How may I do this with substring? With PHP
$rest = substr("jKsuSportTopics", -3, 1);
$rest2 = substr("jKsuSportTopics", 4, 0);
The second argument is the starting index, and the third argument is the length of the string. If the 3rd argument is missing, you'll 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 the
start'th position instring, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.[...]
If
lengthis given and is positive, the string returned will contain at mostlengthcharacters beginning fromstart(depending on the length of string).[...]
If
lengthis omitted, the substring starting fromstartuntil the end of the string will be returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With