1

我正在尝试做一件事,而且只做一件事。

$embedCode = mysql_real_escape_string('<object width="270" height="227"><param name="movie" value="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="270" height="227"></embed></object>');

现在如果我写...

echo 'CODE = ' . $embedCode;

我得到...

CODE = 

没什么...

想法?

编辑:

好的,所以我的意图不仅仅是打印 $embedCode,而是将它插入数据库,但我得到一个空值。我想我会是个聪明人,但在这里我的简单化方法适得其反。无论如何,重点是,它没有通过我的 mysql 查询。

编辑 2:我正在使用 wordpress 的 $wpdb 对象

function insert_video(){

    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "video_manager"; 

    $embedCode = mysql_real_escape_string('<object width="270" height="227"><param name="movie" value="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="270" height="227"></embed></object>');
    $title  = 'this is my title'; 
    $description = 'this is my description';

    $wpdb->insert( $table_name, array( 'title' => mysql_real_escape_string($title), 'embed_code' => $embedCode, 'description' => mysql_real_escape_string($description) ) );

}

function get_video_block($id){
    insert_video();
    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "video_manager";
    $query = "SELECT * FROM " . $table_name . " WHERE `index` = '$id'"; 
    $results = $wpdb->get_results($query, ARRAY_A);


    $results = $results[0];

    $returnString = $results['title'] . '<br>';
    $returnString .= $results['embed_code'] . '<br>';
    $returnString .= $results['description'] . '<br>';

    return $returnString;

}

并得到结果:

this is my title<br><br>this is my description<br>
4

1 回答 1

1

你正在打印你的 html 好吧。右键单击并查看它应该在那里的源。

mysql_real_escape_string根本不是为了转义 html。

如果您使用 phpmyadmin 查看表中的实际数据会发生什么?如果它不存在,那么问题出在您输入该数据时。

好的,所以您在将其写入表时对其进行了转义,您是否使用其他东西来清理该数据^ 就像 strip_tags 一样?Strip_tags 会删除所有的 html。

wpdb_Class 是否有可能清除该 html?

是的,看看 codex.wordpress.org/Function_Reference/wpdb_Class 你可以 $wpdb->query('query') 运行任何查询,所以只需插入它。如果它有效,你就解决了。

于 2010-08-25T02:40:17.867 回答