Liakat Hossain
Liakat Hossain

Reputation: 1384

String function to grab specified character

I am searching for a string function which will grab 43 or specified character from a long string character. Suppose: $char = “this is string and its more than 43 character and function will grab only 43 characters from first”

Please help me

Thanks in advance

Upvotes: 0

Views: 38

Answers (2)

Sarvap Praharanayuthan
Sarvap Praharanayuthan

Reputation: 4360

Use PHP substr.

<?php
$char = substr($char, 0, 43); // strip the value to 43 in length and store in the same variable, where 43 is the desired length
?>

Upvotes: 1

user2959229
user2959229

Reputation: 1355

Use substr(). This will allow you to select any number of characters from a given offset from a source string.

$char = 'this is string and its more than 43 character and function will grab only 43 characters from first';
$num_chars = 43;
$string = substr($char, 0, $num_chars);

Upvotes: 0

Related Questions