嘿, 我有这段代码,我把wordpress文章内容放进一个变量里,并且与第一句相比,在h2标题内,其余部分在段落内。脚本承认第一句话,把它放在一个标题里面,其余的放在一个段落里
1.问题是这个......我的脚本只能识别。要么 !要么 ?在第一次犯罪结束时。 我可以让它识别“...”暂停点吗?
2,如果在我的wordpress后我有这样的文字:
第一森泰斯!其次是一些文字
比我按下回车键
继续与更多的文字
我的剧本只显示“第一森泰斯!其次是一些文本”并没有什么后,进入我的打击。为什么?和ideeas?
下面是代码:
ob_start();
the_content();
$old_content = ob_get_clean(); // I put wordpress inside a variable
$content = strip_tags($old_content); // I use strip tags
preg_match('/(.*?[?.!])(.*)/', $content, $match);
$first_sentence = $match[1];
$the_rest = $match[2];
if ($first_sentence != '' && $the_rest != ''):
echo '<h2>'.$first_sentence.'</h2>';
echo '<p>'.$the_rest.'</p>';
else:
echo '<h2>About me:</h2>';
endif;
嘿,谢谢你,但是当wordpress为我提供“输入”空间的内容时,那部分为什么只能用于内容直到它进入“输入”空间? – webmasters 2011-03-16 19:30:41
顺便说一下,preg match不起作用,为什么ideyas? – webmasters 2011-03-16 19:35:55
呃...是的,它一定是因为它preg_match作为第三个参数需要引用,所以你必须在使用它之前定义该变量。 '$ match = null; preg_match ...' – Slava 2011-03-16 19:41:02