I want to get plain text from Html in PHP. Have tried https://github.com/mtibben/html2text library but seems to be failing in some scenarios. I'll be header tags, paragraph and div tags in my html and need to just return plain text from it.
Below is the code I tried
require_once('class.html2text.inc');
// The “source” HTML you want to convert.
$html = '<div class="mozaik-inner" style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:22.4px;color:rgb(68,68,68);padding:0px 30px;margin:0px auto;width:600px;background-color:rgb(250,250,250);"><h2 style="font-family:Arial, Helvetica, sans-serif;font-size:18px;line-height:28.8px;color:#444444;padding:0px;margin:0px;">Account Details for $account_name :</h2><p style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:22.4px;color:#444444;padding:0px;margin:0px;">TOID: $account_to_id_c</p><p style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:22.4px;color:#444444;padding:0px;margin:0px;"> </p></div>';
// Instantiate a new instance of the class. Passing the string
// variable automatically loads the HTML for you.
$h2t =& new html2text($html);
// Simply call the get_text() method for the class to convert
// the HTML to the plain text. Store it into the variable.
$text = $h2t->get_text();
echo $text;
The issue is my html has Account Details for $account_name
which is incorrectly converted to all uppercase as well as removes $account_name
I need a way to get text from html. div,p,heading tags might be converted to new lines.
Expected Output :
Account Details for $account_name :
TOID: $account_to_id_c