在PHP中将HTML Dom转换为字符串[关闭]

An HTML DOM Contains characters such as id="xyz" or class:'col-md-3'. The problem is I have a PHP script which converts PHP variable to strings. But one of my variable contains HTML dom elements. I am having a hard time to convert that variable into a string.

My code:

 foreach($result as $n){

$message1 = '"'.(string)$n['Message'].'"';
$message = "'".(string)addslashes($message1)."'";

{

error:

/><br /><table style=\'border:1px solid...
                             ^ - error 1
AT <span id="cat_id"
            ^ - error 2
",\"
  ^ -error 3

I am not what you really want to achieve but something like below could help I guess.

$message = "'".(string)addslashes('"'.$messag1.'"')."'";
echo $message;