1

How can I cut the first 11 characters from a string, I would like to display some name of some images, but all my images has 11 random characters and a _ before the actual name of the picture shows, I would like to get rid of these 11 characters before displaying the name.

I tried this:

substr($foto_filename,0,11)

But it does the opposite.

Athax
  • 200
  • 1
  • 12

6 Answers6

4
<?php $str = "The quick brown fox jumps over the lazy dog.";
echo $str2 = substr($str,11);
?>
Vivek Singh
  • 2,453
  • 1
  • 14
  • 27
3

Read the manual.

substr($foto_filename, 11);
yergo
  • 4,761
  • 2
  • 19
  • 41
  • 2
    @Athax Maybe do a lot more research before you ask these kind of questions? – Loko Mar 27 '15 at 08:54
  • 1
    May be early morning. He obviously read at least something ;) Btw, its possible to accept answer that helped by clicking "check" mark under upvote/downvote arrows. – yergo Mar 27 '15 at 08:59
  • @yergo Thanks for the headsup, I checked the answer now. – Athax Mar 27 '15 at 09:07
0
$srt = substr(trim($string), 11);
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Saty
  • 22,443
  • 7
  • 33
  • 51
0

$name = '0123456789A_Image.png';

echo substr ( $name, 0 , 11 ); // 0123456789A

echo substr ( $name, 11 ); // _Image.png

echo substr ( $name, 12 ); //Image.png

substr() PHP.NET

wmid32
  • 1
0

Try this,

$string = "How can i cut the first 11 characters from a string?";
echo substr($string , 11, strlen($string));

11 : indicate start position
strlen($string) : last position of the string

Reference : PHP - Substr

Rakesh Singh
  • 1,250
  • 9
  • 8
  • `strlen($string)-11` to be canonical with manual. Such answer may bring some misunderstoodment. – yergo Mar 27 '15 at 09:05
0

Try this

$str = "thisisasamplestring";
$count = strlen($str);
echo substr($str, (11-$count), ($count-11));

http://sandbox.onlinephpfunctions.com/code/5e8796f9b1dfb2394bbd37e6638dff3fdd4f5e1d