How can substr() function be used to extract the first 140 characters of a string in PHP?
To extract the first 140 characters of a string in PHP, you can use the substr() function. This function allows you to specify the starting position and the length of characters to extract from the string. By passing the string and the length of characters you want to extract as parameters to substr(), you can easily retrieve the desired portion of the string.
$string = "This is a sample string that contains more than 140 characters. Let's extract the first 140 characters using substr() function.";
$first_140_chars = substr($string, 0, 140);
echo $first_140_chars;
Related questions
-
real-time RPG time PHP calculations
-
SQL injection prepared statements mysqli_query
-
whitelists filtering characters