为什么这个数总是返回1?

Lin*_*e57 3 php regex function count

我有以下函数来计算标记中的字符数.输出总是'1',即使我知道它是一个数字以上的事实.我究竟做错了什么?

$www = $_POST['url'];
$url = file_get_contents($www);
Run Code Online (Sandbox Code Playgroud)

[更多代码]

function countTitle() {
global $url;
$search = "/\<title\>(.*)\<\/title\>/";

preg_match($search, $url, $result);

$title = $result[1]; // to string
$counttitle = count($title);
echo $counttitle;   
}
Run Code Online (Sandbox Code Playgroud)

我知道正则表达式有效,因为我使用以下函数来回显标题标记:

function getTitle() {
global $url;
$search = "/\<title\>(.*)\<\/title\>/";

preg_match($search, $url, $result);

$title = $result[1]; // to string
echo $title;
}
Run Code Online (Sandbox Code Playgroud)

Wou*_*r J 10

使用strlen( $str )计数的字母:

$myStr = 'Hello world';
echo strlen($myStr); // outputs 11
Run Code Online (Sandbox Code Playgroud)

Strlen意味着Str ing Len gth .