zoukankan      html  css  js  c++  java
  • Atitit.jsou html转换纯文本 java c# php

    Atitit.jsou html转换纯文本 java c# php

     

    1原理<p> <h> <li><div> lable转换为回车1

    2调用2

    3Php的实现strip_tags2

    4参考2

     

    1. 原理<p> <h> <li><div> lable转换为回车

     

       "'&(quot|#34);'i", // 替换 HTML 实体

    作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

    转载请注明来源: http://blog.csdn.net/attilax

     

     

    public void head(Node nodeint depth) {

    String name = node.nodeName();

    if (node instanceof TextNode)

    append(((TextNode) node).text());

    else if (name.equals("li"))

    append("\n * ");

    }

     

    public void tail(Node nodeint depth) {

    String name = node.nodeName();

    if (name.equals("br"))

    append("\n");

    else if (StringUtil.in(namenew String[] { "p""h1""h2""h3",

    "h4""h5" }))

    append("\n\n");

    else if (name.equals("a"))

    append(String.format(" <%s>",

    new Object[] { node.absUrl("href") }));

    }

     

    private void append(String text)

     

     

    2. 调用

    public static void main(String[] args) {

    pathx.isWebPathMode = true;

    String f = pathx.classPath() + "/com/attilax/cms/cms_tmplt.html";

    String txt = filex.read(f);

    Document doc = Jsoup.parse(txt);

    // Document doc = Jsoup.connect(url).get();

    String plainText;

    HtmlToPlainText formatter = new HtmlToPlainText();

    plainText = formatter.getPlainText(doc);

    System.out.println(plainText);

     

    String x = "工作时间:08:00-22:00\r\n性别要求:男女不限";

    x = plainText;

    @SuppressWarnings("rawtypes")

    Map m = new RowParser().parse(x);

    System.out.println(AtiJson.toJson(m));

    System.out.println("---f");

     

    }

     

    3. Php的实现strip_tags

    string strip_tags(string str[,string allowable_tags])

    4. 参考

     

    Jsoup代码解读之一-概述 - ImportNew.htm

    PHPHTML转换成纯文本内容实例-Php常用代码-Php教程-壹聚教程网.htm

  • 相关阅读:
    php redis 操作大全
    迟到的2017读书计划
    将博客搬至CSDN
    maven安装教程
    liunx centOS6.5安装jdk教程
    centOS6.0虚拟机ip配置
    html网页调用本地exe程序的实现方法:
    org.springframework.beans.factory.BeanCreationException 解决异常错误
    sqlserver查看锁表进程及对锁定的表进行解锁
    tomcat免安装版做成windows系统服务
  • 原文地址:https://www.cnblogs.com/attilax/p/15198706.html
Copyright © 2011-2022 走看看