gpt4 book ai didi

php - 过滤 JavaScript 输出的 HTML

转载 作者:行者123 更新时间:2023-11-28 02:08:09 27 4
gpt4 key购买 nike

我使用 PrettyPhoto API 通过以下代码手动打开灯箱:

api_images  ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
api_titles = ['Title 1','Title 2','Title 3'];
api_descriptions = ['Description 1','Description 2','Description 3']
$.prettyPhoto.open(api_images,api_titles,api_descriptions);

我面临的问题是描述值是从 WordPress 的所见即所得中提取的,并且代码很容易被随机 html 标签、标点符号等破坏

  <script type="text/javascript">
$(document).ready(function() {
$('#menu-item-1006').on('click', function(e) {
e.preventDefault();
var images = new Array();
var descriptions = new Array();
var titles = new Array();
<?php
$i = 0;
$images = new WP_Query(array('post_type' => 'clearance', 'showposts' => -1, 'order' => 'menu_order', 'orderby' => 'ASC'));
if ($images->have_posts()) : while ($images->have_posts()) : $images->the_post();

$featured = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
?>
images[<?php echo $i; ?>] = '<?php echo $featured[0]; ?>';
titles[<?php echo $i; ?>] = '<?php the_title(); ?>'
descriptions[<?php echo $i; ?>] = '<?php echo get_the_content(); ?>';

<?php
$i++;
endwhile;
else:
?>
<?php endif; ?>

$.prettyPhoto.open(images, titles, descriptions);
})
});
</script>

如何过滤 get_the_content() 函数,使其输出没有错误?谢谢!

最佳答案

一个简单的解决方案可能是:

替换

<?php echo get_the_content(); ?>

<?php echo preg_replace('/\<[^\>]+\>/s', '', get_the_content()); ?>

关于php - 过滤 JavaScript 输出的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17475264/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com