0

I want to grab only the first 80 characters from a string, $string, using PHP.

Is there a function for that?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
getaway
  • 8,792
  • 22
  • 64
  • 94
  • 1
    possible duplicate of [How do you pull first 100 characters of a string in PHP](http://stackoverflow.com/questions/317336/how-do-you-pull-first-100-characters-of-a-string-in-php) and many others. – shamittomar Dec 25 '10 at 06:21

4 Answers4

1

I think you can use

substr($string, 0, 80);
Naveed
  • 41,517
  • 32
  • 98
  • 131
Ragnar123
  • 5,174
  • 4
  • 24
  • 34
1

$result = substr($string, 0, 80);

Hamish
  • 22,860
  • 8
  • 53
  • 67
0

Check it out: PHP equivilent of Javascript's substring()?

The text below was written by Nick Shepherd on the topic above.

$string = 'Foo Bar!';
$from   = 2;
$to     = 5;
$final_string = substr($string, $from, $to - $from);

or

$string = 'Foo Bar!';
$start  = 2;
$length = 5;
$final_string = substr($string, $start, $length);
Community
  • 1
  • 1
Gondim
  • 3,038
  • 8
  • 44
  • 62
0

Try the substr function like,

 $result = substr($string, 0, 80);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nik
  • 4,015
  • 3
  • 20
  • 16