我想做一两件事,只有一两件事。Mysql的转义字符串的Youtube嵌入代码不工作
$embedCode = mysql_real_escape_string('<object width="270" height="227"><param name="movie" value="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&hl=en_US&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&hl=en_US&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&hl=en_US&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&hl=en_US&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>
你查看HTML文件,或者只显示位的来源是什么? 'mysql_real_escape_string'不是为了转义HTML而设计的;它的目的是为了逃避SQL查询中的东西。因此,它不会逃避标签,只有引号。 – Amber 2010-08-25 02:39:24
我正在查看源代码,并且没有任何内容。不知怎的,我的字符串被杀死了。最终,它的意图是放在数据库中,但我不断地在我的行中得到一个空值。编辑(好吧,它在那里)... – 2010-08-25 02:41:03
你能提供更多的代码上下文吗?也许你的变量超出了范围,或者没有被正确引用? – Amber 2010-08-25 02:43:46