我說PHP,因爲我有這個片段來計算PHP的單詞,也許用jQuery更好?PHP:計算DIV中的單詞
$words = str_word_count(strip_tags($myString));
我有靜態的HTML一些PHP變量混合像這樣一個PHP頁面:
<?php
$foo = "hello";
?>
<html>
<body>
<div>total words: <?= $words ?></div>
<div class="to_count">
<?= $foo ?> <b>big</b> <i>world</i>, how <span>are</span> we today?
</div>
</body>
</html>
我試圖尋找到PHP的輸出緩衝和下滑的ob_start()
和$buffer = ob_get_clean();
圍繞.to_count DIV,但我似乎無法使用PHP頁面頂部的$buffer
來計算單詞。
任何幫助設置我的方式是讚賞,歡呼聲。
我可能會在`.split()`調用之前添加`.trim()`調用,以防萬一有多餘的空格。 Web檢查員的快速測試表明,縮進會被視爲一個單詞。 – 2011-02-17 04:00:26
是的,我正在去jQuery路線,因爲我已經加載了所有需要wordCounts的頁面。謝謝 – FFish 2011-02-17 04:13:36