如何获取字符串的某些部分(在符号中)。 例如:php - 复制字符串的某些部分
$string = 'one two three';
$numSymbols = 7;
%what should I do%
$res_string = 'one two';
请帮忙。
如何获取字符串的某些部分(在符号中)。 例如:php - 复制字符串的某些部分
$string = 'one two three';
$numSymbols = 7;
%what should I do%
$res_string = 'one two';
请帮忙。
您正在寻找substr函数,我会说。
在你的情况,这里有一个例子:
$string = 'one two three';
$numSymbols = 7;
$res_string = substr($string, 0, $numSymbols);
var_dump($res_string);
,你会得到:
string 'one two' (length=7)
参数:
使用PHP的方法substr
:
$string = 'one two three';
$numSymbols = 7;
$res_string = substr($string, 0, $numSymbols);
您应该使用substr( )
例子:
$string = 'one two three';
$res_string = substr($string, 0, 7);// $res_string == 'one two'
* “在你* R *案” – arbales 2009-09-13 09:09:56
@arbales:这是尝试键入太快的问题:-(谢谢!我编辑了这个错字(和其他一些错误) – 2009-09-13 09:11:19