嘿, 我有這段代碼,我把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