2015-02-11 25 views
1

如何使用PHP統計單個HTML行(不包括標籤但包括​​空格)上的字符?如何用PHP計算單個html行上的字符數

enter image description here

後,我知道字符在一個單一的HTML線(包括空格),我需要再算上一個鏈接的字符(如果有一個人也沒有)和之前的字符最大數量|之後。

enter image description here

故有此信息

  • 最大行字符。
  • if link:characters before |之後和本身。

HTML示例:

<p>Line one Line one Line one Line one Line one Line Line one Line one 
    Line two Line two Line two Line two <a href="#link">LINK</a> Line two 
    Line three Line three Line three Line three Line three Line three</p> 

PHP的:

讀線之一,數最多字符,並且鏈接,然後

如果鏈接:鏈接數字符加上之前|後。 與數組排列

"before linked text, amount of characters" 
"linked text, amount of characters" 
"after linked text, amount of characters" 

任何幫助或洞察將是偉大的!謝謝你的時間。

回答

0

使用strlen()

例子:

$str = 'hello world'; 
$length = strlen($str); 
echo $length; //returns 11 

View Documentation Here

+0

謝謝您的回答(我知道應該使用strlen),但我怎麼算前後和鏈接本身? – Benjamin 2015-02-11 03:05:13

+0

鏈接是靜態還是會改變? – 2015-02-11 03:12:42

+0

鏈接將改變,大部分時間甚至不會有一個,但它可能出現在該行的任何地方。 – Benjamin 2015-02-11 03:19:58