我正在搜索一个字符串函数,它将从长字符串字符中获取43或指定的字符。假设:$char = “this is string and its more than 43 character and function will grab only 43 characters from first”
请帮帮我
提前致谢
答案 0 :(得分:1)
使用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
?>
答案 1 :(得分:0)
使用substr()
。这将允许您从源字符串的给定偏移量中选择任意数量的字符。
$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);