Athax
Athax

Reputation: 182

How can i cut the first 11 characters from a string?

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

Answers (6)

Saty
Saty

Reputation: 22532

$srt = substr(trim($string), 11);

Upvotes: 0

user2560539
user2560539

Reputation:

Try this

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

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

Upvotes: 0

Rakesh Singh
Rakesh Singh

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

wmid32
wmid32

Reputation: 1

$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

Upvotes: 0

Vivek Singh
Vivek Singh

Reputation: 2447

<?php $str = "The quick brown fox jumps over the lazy dog.";
echo $str2 = substr($str,11);
?>

Upvotes: 4

yergo
yergo

Reputation: 4980

Read the manual.

substr($foto_filename, 11);

Upvotes: 3

Related Questions