我怎么把文本编辑器里面的假如:bb=<P>&nbsp;</P>
<TABLE cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR>
<TD vAlign=top width=657 colSpan=6>
<P align=center><B>贝川通讯录</B></P></TD></TR>
<TR>
<TD width=109>
<P align=left><B>办公室</B></P></TD>
这样的东西给转换成aa=&lt;TABLE style=&quot;WIDTH: 506pt; BORDER-COLLAPSE: collapse&quot; cellSpacing=0 cellPadding=0 width=674 border=0 x:str&gt;这样保存到数据库,
这样转换的代码好有在保存到数据库的里面的aa在调取出来的时候在还原成页面形式?请高手赐教…………急急………………

解决方案 »

  1.   

    PHp怎么实现上面的转换?
    我怎么把文本编辑器里面的假如:
    bb= <P>&nbsp; </P> <TABLE cellSpacing=0 cellPadding=0 border=1> <TBODY> <TR> <TD vAlign=top width=657 colSpan=6> <P align=center> <B>贝川通讯录 </B> </P> </TD> </TR> <TR> <TD width=109><P align=left> <B>办公室 </B> </P> </TD> bb转换成aa=&lt;TABLE style=&quot;WIDTH: 506pt; BORDER-COLLAPSE: collapse&quot; cellSpacing=0 cellPadding=0 width=674 border=0 x:str&gt;将aa这样保存到数据库, 在保存到数据库的里面的aa在调取出来的时候在还原成页面形式的字符转换?请高手赐教…………急急………………
      

  2.   

    html_entity_decode()函数转一下。
      

  3.   

    htmlspecialchars()这个是转换成html实体,和html_entity_decode()这个有区别吗
      

  4.   

    htmlspecialchars()
    据特殊字符转成实体,用它就行了 html_entity_decode()所有字符转成实体
      

  5.   


    //存入的时候
    $strTmp = ereg_replace('<', '&lt;', $strTmp);
    $strTmp = ereg_replace('>', '&gt;', $strTmp);//取出的时候
    $strTmp = ereg_replace('&lt;', '<', $strTmp);
    $strTmp = ereg_replace('&gt;', '>', $strTmp);
      

  6.   

    不用那么麻烦!用htmlentities或者htmlspecialchars都可以把html的特殊字符替换掉楼主那种&lt;等那种形式
      

  7.   

    html_entity_decode
    htmlentities
    是两个相反的函数.<?php
    $str = "A 'quote' is <b>bold</b>";// 输出: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str);// 输出: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str, ENT_QUOTES);
    ?>
    <?php
    $orig = "I'll \"walk\" the <b>dog</b> now";$a = htmlentities($orig);$b = html_entity_decode($a);echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; nowecho $b; // I'll "walk" the <b>dog</b> now
    // PHP 4.3.0 之前的版本将作如下处理
    function unhtmlentities($string)
    {
        // 数値属性转换
        $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
        $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
        // 字串属性转换
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
        $trans_tbl = array_flip($trans_tbl);
        return strtr($string, $trans_tbl);
    }$c = unhtmlentities($a);echo $c; // I'll "walk" the <b>dog</b> now?>