How to remove the first number in a line?

How to delete the first number in a line? Say, if I had 48 numbers separated by a "," (comma):

8,5,8,10,15,20,27,25,60,31,25,39,25,31,26,28,80,28,27,31,27,29,26,35,8,5,8,10,15,20,27,25,60,31,25,39,25,31,26,28,80,28,27,31,27,29,26,35 

How to remove "8" from a string? Thanks.

+4
source share
7 answers
 substr(strchr("2512,12512,1245234,23452345", ","), 1) 

in fact. This is the most efficient way, I think, because of this, not converting the string to an array or something like that. He just cut off the line.

+8
source
 $text = "8,5,8,10,15,20,27,25,60,31,2"; 

First you can explode:

 $array = explode(',', $text); 

Then remove the first element:

 array_shift($array); 

End on the last, join:

 echo implode(',' $array); 
+7
source

The following assumes that you have at least 2 numbers (and fast):

 list($first, $rest) = explode(',', $string, 2); 

This will work for single numbers (but uses a regex):

 preg_replace('/^.*?,/', '', $string); 
+7
source

Deletes all characters to the first comma and turns it on:

 ltrim(strstr($numbers, ','), ','); 

Deletes all digits up to the first comma and includes the first comma:

 ltrim(ltrim($numbers, '01234567890'), ','); 

A slightly faster version that deletes all digits before and includes the first digit

 substr($numbers, strspn($numbers, '1234567890')+1); 
+2
source

Everyone provides a different solution, so here is another simple solution.

 $mystring = "8,5,8,10,15,20,27,25,60,31,25,39,25,31"; $pos = strpos($mystring, ","); $pos1 = $pos+1; // add the comma position by 1 echo substr($mystring, $pos1); 
+2
source

How does it work if "8" is greater than 9!

 $numbers = substr($numbers, strpos($text,",") + 1); 
0
source
 substr(strstr("8,5,8,10,15,20,27,25,60,31,25,39,25,31",","),1); 
0
source

Source: https://habr.com/ru/post/1307448/


All Articles