假设我有以下字符串:
$str = "PHP code may be embedded into HTML or HTML5 markup, or it can be used in combination with various web template systems, web content management systems and web frameworks.";在这里,我打印的子字符串从单词“组合”开始,并以“内容”结尾
echo substr($str, strpos($str, 'combination'), strpos($str, 'content'));它是从‘组合’到最后的打印,而不是向上的‘内容’。第三个参数有什么问题吗?
发布于 2017-05-15 08:34:04
substr的第三个参数应该是字符串长度,而不是结束位置。
$i = strpos($str, 'combination');
echo substr($str, $i, strpos($str, 'content') - $i);https://stackoverflow.com/questions/43974738
复制相似问题