2

I want to remove all greater than and less than symbols. I do NOT want to remove the contents between those symbols and I do NOT want to remove br tags. Is there any way to do this? Keep in mind I have no idea how to use Regex.

This is what I have so far:

/[<>](?!b)/g

If I use that regex on this:

< >"' <<< <   <  <br> <aaa > >

Then I get this:

 "'       <br aaa  

But I want this:

 "'       <br> aaa  

Please help! (ノ´ロ`)ノ

EDIT: (To show the answer and use) Function to print the contents of php "objects" for troubleshooting, etc.

function myPrint($myPrint, $returnAsString = FALSE){
    if($myPrint === FALSE){ $myPrint = "FALSE"; }
    if($myPrint === TRUE){ $myPrint = "TRUE"; }
    if($returnAsString === TRUE){
        return preg_replace(array("/\s/", "/<(?!br>)/", "/(?<!<br)>/"), array("&nbsp;","&#60;","&#62;"), nl2br(print_r($myPrint, true),false));
    }
    else{
        echo preg_replace(array("/\s/", "/<(?!br>)/", "/(?<!<br)>/"), array("&nbsp;","&#60;","&#62;"), nl2br(print_r($myPrint, true),false))."<br>";
        return;
    }
}
Eric Shoberg
  • 106
  • 1
  • 10

1 Answers1

1

Typically it's easily done with a couple of assertions.

<(?!br>)|(?<!<br)>

Expanded

   <
   (?! br> )
|  
   (?<! <br )
   >