Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何只显示标签而不显示数字?_Php_String_Wordpress_Tags_Remove If - Fatal编程技术网

Php 如何只显示标签而不显示数字?

Php 如何只显示标签而不显示数字?,php,string,wordpress,tags,remove-if,Php,String,Wordpress,Tags,Remove If,我需要一个解决方案,使我能够在下面的wordpress页面上只显示不包含数字的标签列表 这是我的代码: <?php $tags_html = ''; foreach($tags as $single_tag) { $count++; if (1 == $count) { $tags_html .= '<a href="'.get_term_link($single_tag, 'spot_tags').'"&

我需要一个解决方案,使我能够在下面的wordpress页面上只显示不包含数字的标签列表

这是我的代码:

<?php

        $tags_html = '';
            foreach($tags as $single_tag) 
             {

$count++;
if (1 == $count)
 {
  $tags_html .= '<a href="'.get_term_link($single_tag, 'spot_tags').'">'.$single_tag->name.'</a>, ';
}
                //// ADDS TO OUR MARKUP

            }
            //// TRIMS LAST COME
            echo rtrim($tags_html, ', ');

        ?>
    </span> 



    <?php }
    ?>

不应显示属于包含数字的帖子/列表的所有标记,不包含数字的标记可以显示在列表下方


有什么想法吗?

我不知道
$single_tag
的确切结构,除非你发布一个
var_dump()
,但是下面是
如果
你需要阻止显示带有数字内容的标签的代码:

if(!preg_match('/\d/',$single_tag))
{
    $tags_html .= '<a href="'.get_term_link($single_tag, 'spot_tags').'">'.$single_tag->name.'</a>, ';
}
if(!preg_match('/\d/',$single_标记))
{
$tags_html.=',';
}

它使用检查字符串是否包含数字。

如果您的标记位于字符串中,则需要这两行(用于构建数组)

否则,如果您的标记已经在一个数组中,如下图所示,则不需要上面的标记

$tags = array('34hj', 'wer', 'wer35', 'rwer', '5345', '5dgg45', 'sdfa');
最后,您需要这个代码段,它将排除包含任何数字的标记

foreach($tags as $tag) {
    if(preg_match('/^[^\d]+$/', $tag));
    echo trim($tag) . "\n";
}

foreach($tags as $tag) {
    if(preg_match('/^[^\d]+$/', $tag));
    echo trim($tag) . "\n";
}