如何使用PHP计算单个html行上的字符 [英] How to count characters on a single html line with PHP

查看:127
本文介绍了如何使用PHP计算单个html行上的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHP计算单个HTML行上的字符(不包括标记,但包括空格)?

how do I count characters on a single HTML line (not including tags but including spaces) with PHP?

在我知道单个HTML行上的最大字符数(包括空格)我需要计算一个链接的字符(如果有一个)和之前的字符。

After I know the max amount of characters on a single HTML line (including space) I need to then count the characters of a link (if there's one there) and characters before|after.

这样的信息:


  • 最多行字符。

  • 如果link:|之前的字符

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:

计数最大字符,如果链接,则

read line one, count max characters and if link, then

if Link:count link characters before |后。
在链接文本之前使用

if Link: count link characters plus before | after. make array with

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

任何帮助或见解大!谢谢你的时间。

Any help or insight would be great! thanks for your time.

推荐答案

使用strlen()

示例:

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

在此查看文档

这篇关于如何使用PHP计算单个html行上的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆