Jump to content

[SOLVED] Show first few character of a string


abdfahim

Recommended Posts

To return the first 9 characters:

[code]
$test = "This is the string";

$output = substr($test, 0, 8);

echo $output;
// This is t
?>
[/code]

It doesn't return "he" because PHP counts whitespace as a character.

EDIT: I accidentally pressed Preview so the reply never got sent. Also, you would use 0 and 8, not 9, because 0 - 8 is 9, 0 - 9 is 10.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.