getaway
getaway

Reputation: 8990

Get a number of characters from a string using PHP

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

Is there a function for that?

Upvotes: 0

Views: 144

Answers (4)

Nik
Nik

Reputation: 4075

Try the substr function like,

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

Upvotes: 0

Ragnar123
Ragnar123

Reputation: 5204

I think you can use

substr($string, 0, 80);

Upvotes: 1

Hamish
Hamish

Reputation: 23316

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

Upvotes: 1

Gondim
Gondim

Reputation: 3048

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);

Upvotes: 0

Related Questions