Removing HTML Tags from String Variables using PERL Regular Expressions via PHP

Category: Software and Systems Engineering
Author: Sean O'Donnell
Thu, Feb. 20th, 2003 @ 2:20:22 (MST)

This example will demonstrate how to Remove HTML Code from a blob of text using PERL Regular Expressions in PHP

This is a rather simple function, and is very handy for many uses throughout a dynamic website, so I thought I should give an example using PERL Regular Expressions via PHP

<?php
/**
* html_remove($str)
* remove any html tags from a string/blob
*/
function html_remove($str){
    return 
preg_replace("/<[^>]*>/","",$str);
}
?>

Example (Usage):

<?php
print html_remove("<p>Hello World</p>");
?> 

Example (Results):

Hello World

Copyleft (<) 1998-2019 www.seanodonnell.com