html to string javascript code example
Example 1: javascript to string
num.toString();
Example 2: html to string
import { decode } from 'html-entities';
function htmlToString(returnText: string) {
returnText = returnText.replace(/<br>/gi, "\n");
returnText = returnText.replace(/<br\s\/>/gi, "\n");
returnText = returnText.replace(/<br\/>/gi, "\n");
returnText = returnText.replace(/<p.*>/gi, "\n");
returnText = returnText.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)");
returnText = returnText.replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "");
returnText = returnText.replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "");
returnText = returnText.replace(/<(?:.|\s)*?>/g, "");
returnText = returnText.replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\n\n");
returnText = returnText.replace(/ +(?= )/g, '');
returnText = returnText.replace(/<[^>]+>/g, '').replace(/</g, "<").replace(/>/g, ">")
returnText = decode(returnText);
return returnText;
}
Example 3: convert element to html string
html_entity_decode
$temp = "<font class='red font-price'> 30 </font>";
echo html_entity_decode($temp);
Example 4: js variable to string
`String text ${expression}`