问题
I am parsing webpage content using file_get_content()
and then getting plaintext out of that.
Now I want to catch first 150 characters from that plaintext. Here I worked.
DEMo on codepad: DEMO
$data = file_get_contents($url);
$content = plaintext($data); //dont bother about this it works fine
$Preview = trim_display(140,$content);
function trim_display($size,$string)
{
$trim_string = mb_substr($string, 0, 150,'UTF-8');
echo "<br/> here";
echo utf8_decode($trim_string);
return $trim_string;
}
The error supplied on codepad:
Warning: file_get_contents(http://crewow.com/CSS_Layout_Tutorial.php): failed to open stream: No such file or directory on line 3
Fatal error: Call to undefined function mb_substr() on line 9
回答1:
mbstring
extension is not installed in your apache, you need to install that.
Fatal error: Call to undefined function mb_substr() - means that “mbstring” PHP extension is not installed or not enabled on your hosting server.
mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience
来源:https://stackoverflow.com/questions/20222999/substr-or-mb-substr-does-not-work