Reputation: 182
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.
Upvotes: 1
Views: 294
Reputation:
Try this
$str = "thisisasamplestring";
$count = strlen($str);
echo substr($str, (11-$count), ($count-11));
http://sandbox.onlinephpfunctions.com/code/5e8796f9b1dfb2394bbd37e6638dff3fdd4f5e1d
Upvotes: 0
Reputation: 1260
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
Upvotes: 0
Reputation: 1
$name = '0123456789A_Image.png';
echo substr ( $name, 0 , 11 ); // 0123456789A
echo substr ( $name, 11 ); // _Image.png
echo substr ( $name, 12 ); //Image.png
Upvotes: 0
Reputation: 2447
<?php $str = "The quick brown fox jumps over the lazy dog.";
echo $str2 = substr($str,11);
?>
Upvotes: 4