简体   繁体   English

如何从文本行中减去某些字符串并获取剩余的字符串

[英]How do i substr certain string from a text line and get the remaining

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: 我的解决方案中有12345678910的文本行,我想使用尝试过的函数substr()在一行中获得8910

$text = "12345678910";
$pay = substr($text,0,7);
echo $pay;

But I get 1234567 expected 8910 但我得到1234567预期为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: 因此,您告诉它从字符串的开头开始,并输入7个字符。您可以执行以下操作:

$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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM