4

我正在使用 CKEditor 和 CKFinder。两者都工作正常。当我浏览(或直接复制)图像(或闪存)到 CKEditor 时,它会显示在其中并插入到 MySql 数据库中。

将其插入 MySql 数据库后,我尝试将其显示在不显示的 HTML 表中,并显示替代文本。

通过 CKFinder 浏览图像后的图像路径如下所示。

<img alt="" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style="width: 490px; height: 618px;" />

插入数据库的内容如下。

&lt;img alt=&quot;\&amp;quot;\&amp;quot;&quot; data-cke-saved-src=&quot;\&quot; 

src=&quot;\&amp;quot;/ckfinder/userfiles/images/1243_SS_2502.jpg\&amp;quot;&quot; st  yle=&

quot;\&amp;quot;width:&quot; 490px;=&quot;&quot; height:=&quot;&quot; 618px;\&quot;= quot;&quot;&gt;

试了htmlentities()还是不行。在使用 JSTL/EL 处理 JSP 时,我必须执行以下操作。

<c:out value="${str}" default="No content found." escapeXml="false"/>

escapeXml="false",其中str用EL写的是一个java.lang.String保存转换后的Oracleclob数据。

在 PHP 中解决这种情况的方法是什么?CKEditor 和 CKFinder 对我来说都很好。


$ckeditor = new CKEditor();
$ckeditor->basePath = 'ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('description', $ed_about_us);

编辑:

<?php include_once("Lock.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Wagafashion</title>

<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<!--<script type="text/javascript" language="javascript" src="ckeditor/ckeditor.js"></script>-->
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>        
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>

<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script><script>
    jQuery(document).ready(function(){
        // binds form submission and fields to the validation engine
        jQuery("#dataForm").validationEngine();
    });            
</script>

<script language="javascript" type="text/javascript">
    function deleteSingle(id)
    {       
        var delId=confirm("About us with the id "+id+" is about to be deleted permanently.\n\nAttention : This action will never be undone!\n\nAre you sure...???");        
        return(delId==true?true:false);
    }

</script>

</head>

<body>
<?php
    include_once("Connection.php");
    include_once("ckeditor/ckeditor.php");
    $con=new Connection();
    $con->get_connection();

    $ed_about_us="";
    $flag=-1;
    $msg="";

    if(isset($_POST['btnSubmit']))
    {
        $act=trim($_POST['param_action']);
        $about_us=$_POST['cms_description'];        

        if($act=="add")
        {   
            $res=$con->get_data("select count(*) as cnt from cms"); 
            $cnt_cmt=mysql_result($res, 'cnt');

            if($cnt_cmt==0)
            {
                $flag=$con->iud("insert into cms (about_us)values('".mysql_real_escape_string(urlencode($about_us))."')");              
            }
            else
            {
                $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."'");
            }

            if($flag==1)
            {
                $msg="Insertion done successfully.";        
            }
            else if($flag==0)
            {
                $msg="Insertion failed - reason : ".mysql_errno()." : ".mysql_error();  
            }
        }
        else if($act=="edit")
        {
            $cms_id=$_POST['cms_id'];
            $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."' where id=".$cms_id."");               
            if($flag==1)
            {
                $msg="About us has been updated successfully.";
            }
            else if($flag==0)
            {
                $msg="Updation failed - reason : ".mysql_errno()." : ".mysql_error();   
            }           
        }
    }           
    else if(isset($_GET['ed_id']))
    {
        $ed_res=$con->get_data("select about_us from cms where id=".$_GET['ed_id'].""); 

        while($row=mysql_fetch_assoc($ed_res))
        {
            $ed_about_us=$row['about_us'];      
        }
    }   
    else if(isset($_GET['del_id']))
    {
        $flag=$con->iud("update cms set about_us='' where id=".$_GET['del_id']);
        if($flag==1)
        {
            $msg="About us been deleted successfully.";
        }
        else if($flag==0)
        {
            $msg="Can not delete - reason : ".mysql_errno()." : ".mysql_error();    
        }
    }
    else if(isset($_POST['btnDelete']))
    {
        $set_del=$_POST['setDel'];
        $flag=$con->iud("update cms set about_us='' where id in($set_del)");
        $size=sizeof(split(",", $set_del));

        if($flag==1)
        {
            if($size==1)
            {
                $msg="1 row deleted.";  
            }
            else
            {
                $msg=$size." rows deleted.";    
            }           
        }
        else if($flag==0)
        {
            $msg="Can not perform deletion - reason : ".mysql_errno()." : ".mysql_error();  
        }       
    }
?>

    <?php include("tamplate/Template1.php");?>
        <h2>About Us</h2>
    <?php include("tamplate/NewTemplate.php");?>

    <?php
        if($flag==1)
        {        
            echo "<p>";
            ?>
                <!--[if !IE]>start system messages<![endif]-->
                <ul class="system_messages">                                     
                    <li class="green"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>                    
                </ul>
                <!--[if !IE]>end system messages<![endif]-->
            <?php               
            echo "</p>";
        }
        else if($flag==0)
        {     
            echo "<p>";
            ?>
                <!--[if !IE]>start system messages<![endif]-->
                <ul class="system_messages">                    
                    <li class="red"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>                                        
                </ul>
                <!--[if !IE]>end system messages<![endif]-->
            <?php               
            echo "</p>";    
        }
    ?>
<img alt=\"\" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style=\"width: 490px; height: 618px;\" />
      <!--[if !IE]>start forms<![endif]-->
    <form action="<?php $_SERVER['PHP_SELF']; ?>" id="dataForm" name="dataForm" method="post" class="search_form general_form">
        <!--[if !IE]>start fieldset<![endif]-->
        <fieldset>
            <!--[if !IE]>start forms<![endif]-->
            <div class="forms">

            <!--[if !IE]>start row<![endif]-->
            <div class="row">   
            <?php
                $ckeditor = new CKEditor();
                $ckeditor->basePath = 'ckeditor/';
                $ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
                $ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
                $ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
                $ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
                $ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
                $ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
                $ckeditor->editor('cms_description', urldecode($ed_about_us));

            ?>             

            <!--[if !IE]>start row<![endif]-->
            <div class="row">
                <div class="buttons">                                                                                                                                                   
                        <span class="button send_form_btn"><span><span>Submit</span></span><input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" onclick="return validate();"></span>                    
                </div>
            </div>
            <!--[if !IE]>end row<![endif]-->
            </div>
        </fieldset>

        <!--[if !IE]>end fieldset<![endif]-->                
        <input type="hidden" id="param_action" name="param_action" value="

            <?php
                if(isset($_GET['ed_id']))
                {
                    echo "edit";        
                }
                else
                {
                    echo "add"; 
                }
            ?>
            " />

            <input type="hidden" id="cms_id" name="cms_id" value="<?php echo isset($_GET['ed_id'])?$_GET['ed_id']:"";?>" />            
    </form>            

    <?php include("tamplate/Template2.php");?>
        <h2>About Us</h2>
    <?php include("tamplate/NewTemplate1.php");?>   


    <form action="<?php echo $_SERVER['PHP_SELF'];?>" id="mainForm" name="mainForm" method="post">                                                

        <?php include("tamplate/ExtraTemplate.php");?>      

            <table cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                <th style="width: 10px;">Check</th>
                <th style="width: 450px;">About Us</th>                
                <th style="width: 10px;">Actions</th>

                <?php

                    $get_data=$con->get_data("select id, about_us from cms order by id");
                    $cnt=1;$flag='';

                    while($data_row=mysql_fetch_assoc($get_data))
                    {
                        extract($data_row); 
                        $cnt%2==0?$flag="second":$flag="first";
                        ++$cnt;

                        echo "<tr class='$flag'>";
                        echo "<td><input type='checkbox' name='chk' value='$id'></td>";
                        echo "<td>".urldecode($about_us)."</td>";

                        echo "<td><div class='actions'><ul><li><a href='".$_SERVER['PHP_SELF']."?ed_id=$id' class='action2'></a></li>";
                        echo "<li><a href='".$_SERVER['PHP_SELF']."?del_id=$id&table_name=cms&pri=id' onclick='return deleteSingle($id);' class='action4'></a></li></ul></div></td>";
                        echo "</tr>";
                    }
                ?>

                </tbody>
            </table>    
            <input type='hidden' id='setDel' name='setDel'/>
            <?php include("tamplate/Template3.php");?>         
    </form>
    <?php include("tamplate/Template4.php");?> 
</body>
</html>
4

1 回答 1

1

您是否尝试使用html_entity_decode()来显示内容?它将解码编码的 html 以获得更好的输出。参考这里

编辑
将您的查询更改为以下

insert into cms (about_us) values ('".mysql_real_escape_string(urlecode(stripslashes($about_us)))‌​."')

当您从数据库中获取它时,它使用

urldecode($value)

$value您从数据库中获得的块在哪里。

于 2012-09-04T22:17:22.617 回答