Intelligence Development Program - Lập trình thông minh - Blog về học lập trình, mã nguồn, phần mềm.

Lọc thẻ HTML từ chuỗi, remove HTML tag từ string




Lọc thẻ HTML từ chuỗi, remove HTML tag từ string
1 Remove HTML tags from a string using PHP with the following code:
<?php $htmlstring = preg_replace("/<.*?>/", "", $htmlstring); ?>

This method uses regular expressions to identify the start and end of any HTML tag and strip it from the string. Replace $htmlstring with whatever variable you use.

2 Remove HTML tags from a string on ASP.net with the following code:
{ return Regex.Replace(text, @"<(.|\n)*?>", htmlstring.Empty); }

As in the PHP version, replace "htmlstring" with whatever your string's variable is named.

3 Remove HTML tags from a string using JavaScript if you run into problems with either of the above examples:
function removeHTMLTags(htmlstring){
if(htmlstring){
var stringdiv = document.createElement("div");
stringdiv.innerHTML = htmlstring;
if(document.all) { return stringdiv.innerText; }
else { return stringdiv.textContent; }
} }

Again, replace "htmlstring" with your string's variable.

Nguồn sưu tầm

Ebook