I have a text line of 12345678910
in my solution, I want to get 8910
in one line using the function substr()
I have tried:
$text = "12345678910";
$pay = substr($text,0,7);
echo $pay;
But I get 1234567
expected 8910
Thanks in advance
使用-4作为第二个参数。
echo substr("1234567890", -4);
You've misread the manual, the second parameter is the starting position and the third is the length. So you are telling it to start at the start of the string and go 7 characters in. You could do:
$pay = substr($text,7);
or
$pay = substr($text,7, 4);
or the negative as the other answer suggests.
Just do this.
<?php
$text = "12345678910";
$pay = substr($text,7);
echo $pay;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.