Coder Social home page Coder Social logo

html2text's Introduction

HTML to text renderer for PHP

PHP library to render HTML5 to monospaced text. The concept was created to create text versions of HTML emails. If your software sends HTML email, it is friendly to also send a plain text version of the document. The plain text document is generally used by email clients to create the preview text.

API

render_html_to_text

$text = render_html_to_text($html, [$width=76, [$stylesheet=false]]);

Parameters

  • $html - the HTML document to be rendered. Should be a string.

  • $width - the width of the rendered document. This is import for word wrapping of block elements and tables.

  • $stylesheet - custom styles to be implemented in the rendering. These styles will take preference over the built in stylesheet. Currently, only tags and classes are considered. The specificity of a rule is not considered, so in other words, the first rule to match is the one which will be applied to the element.

    Example: ['p' => ['margin-bottom' => '1em']]

Stylesheet Interpretation

Stylesheets are currently intepreted as matching elements based on simple classes or tag names. Currently, these style properties are supported:

  • border
  • margin
  • padding
  • text-align
  • text-decoration
  • text-transformation
  • white-space

Styles are interpreted in a way to try to convert measurements to the same of a monospaced character. The best way to convey measurements in custom stylesheets is with the em unit. Since em represents the width of character, then the values are used without conversion.

html2text's People

Contributors

greezybacon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.