Remove first 2 characters from a string?

Ok, I know you can use the substr to only pull some of the characters, but can I strip out only some of the characters, but keep the rest.


$stuff=substr($stuff,2);

I believe this will work.

That gives me only the second character in the string. I’m pretty sure substr is really only for if you want some of the characters but not all. I want to remove 2 of the characters.

You didn’t even test the code, did you? Maybe you should… :wink:

Have you tried it out? I just did this and it worked:


<?php
$string='Hello';
$string=substr($string,2);
echo $string; // output 'llo'
?>

Additionally, wanting some of the characters but not all is exactly the same as wanting to remove 2 of the characters–you want all but those two characters.

Ah it worked, I had modified 2 pages for the code, but only uploaded one of them, so my initial value wasn’t correct.

Thanks.

How would I then remove the last 2 characters from the string?

I tried this:


$string = "Hello";
$string = substr($string, -2);
echo $string;

But it outputs lo.

Nevermind, I found it.


 $string = "Hello";
$string = substr($string, 0, -2);
echo $string;