这有点菜鸟问题上的字符串变量返回不正确的字符,但是......PHP SUBSTR从功能的preg_match
我打电话使用的preg_match得到一个字符串的另一个PHP文件的功能。然后我想使用substr来获取该字符串的特定部分,但是它不输出字符串中的任何字符。当我用preg_match
函数替换变量时,我得到正确的输出。
这是基本的代码:
$title = $stream["song1"]; // From a preg_match in an external php file
echo $title; // Correctly prints the song name, in this case "mySong"
echo substr($title, 0, 1); // Outputs a "<" symbol (why??)
如果我运行上面相同的三条线,但硬编码的歌名:
$title = "mySong";
echo $title; // Correctly prints the song name, in this case "mySong"
echo substr($title, 0, 1); // Outputs a "m" symbol (correct)
而且,当我检查变量$title
的类型是,它返回“字符串”。我确信我正在做一些非常愚蠢的事情......任何人都可以帮忙吗?
尝试查看$流[ “松1”]的编码。也许它包含多字节字符串,你需要使用mb_substr。试试strlen($ stream [“song1”]); –