-3

Suppose I have the following string:

 $str = 2-Vsr2343xsf;

I know that the string starts with 2-. I do not know the number of characters in a string.

I need to be able to take off 2- off the start of the string so I am left with Vsr2343xsf

How can I achive this?

Allen S
  • 3,471
  • 4
  • 34
  • 46

2 Answers2

2

Use substr. The first value is the string, the second is the starting character position (in your case, 2 is in position 0, the - is in position 1, etc.). You can also specify a length as a third parameter if you so choose.

$s = substr($str, 2);
randak
  • 1,941
  • 1
  • 12
  • 22
1
$str = 2-Vsr2343xsf;
$str2 = substr($str, 2);

Using substr(). $str2 in the required string.

See this: Remove first 4 characters of a string with PHP

Community
  • 1
  • 1
Eisa Adil
  • 1,743
  • 11
  • 16