函数preg_replace

时间:2016-11-26 11:56:24

标签: php wordpress

嗨我在wordpress中有一个功能

$orders

它删除了blockquote标记,但也删除了array (size=5) 0 => array (size=2) 0 => string 'Prosjekt navn' (length=13) 1 => string 'Antall Timer' (length=12) 1 => array (size=2) 0 => string 'Mitt F�rste Prosjekt' (length=20) 1 => string '72' (length=2) 2 => array (size=2) 0 => string 'Mitt Andre Prosjekt' (length=19) 1 => string '20' (length=2) 3 => array (size=2) 0 => string 'MItt tredje prosjekt' (length=20) 1 => string '5' (length=1) 4 => array (size=2) 0 => string 'et fjerde prosjekt' (length=18) 1 => string '0' (length=1) 任何人都知道如何不删除<?php $string = get_the_content();?> <?php $string = preg_replace('/(<blockquote)(.*)(<\/blockquote>)/', "", $string); ?> <?php echo $string;?>

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

$content = preg_replace('/<blockquote>(.*?)<\/blockquote>/', '', get_the_content());

答案 1 :(得分:0)

我做这样的事情

<?php $the_content = get_the_content();?>
<?php $bad_tags    = ['/(<blockquote)(.*)(<\/blockquote>)/'];?>
<?php $strip_tags  = preg_replace( $bad_tags, "" , $the_content );?>
<?php echo apply_filters( 'the_content', $strip_tags );?>

它删除了blockquote和文本,但保留了所有其余的文本和样式