Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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的输出中添加id_Php_Html_Wordpress - Fatal编程技术网

向某些php的输出中添加id

向某些php的输出中添加id,php,html,wordpress,Php,Html,Wordpress,我有一个小代码 我需要向输出中添加一个类 $output_html .= ' ' . groovy_menu_woocommerce_mini_cart_counter( $qty ) . ' '; 哪个输出a <span class="gm-cart-counter">2</span> 看起来是这样的 <span id="newid"class="gm-cart-counter">2</span> 2 测试新代码 $span = groo

我有一个小代码

我需要向输出中添加一个类

$output_html .= ' ' . groovy_menu_woocommerce_mini_cart_counter( $qty ) . ' ';
哪个输出a

<span class="gm-cart-counter">2</span>
看起来是这样的

<span id="newid"class="gm-cart-counter">2</span>
2
测试新代码

$span = groovy_menu_woocommerce_mini_cart_counter($qty);
$spanWithId = "<span id='the-id'" ;
$span=groovy\u菜单\u woocommerce\u迷你购物车\u计数器($qty);

$spanWithId=“这很难看,但应该可以做到:

$span = groovy_menu_woocommerce_mini_cart_counter($qty);
$spanWithId = "<span id='the-id'" . substr($span, 5, strlen($span));
$output_html .= $spanWithId;

echo "$spanWithId";
$span=groovy\u菜单\u woocommerce\u迷你购物车\u计数器($qty);

$spanWithId=“以下是我要做的

// create a wrapper function that injects the id
function menu_with_id($qty, $id){
  $span = groovy_menu_woocommerce_mini_cart_counter($qty);
  return str_replace('<span', "<span id='$id'", $span);
}

// then replace it
$output_html .= ' ' . menu_with_id($qty, $id) . ' ';
//创建一个注入id的包装函数
带标识的功能菜单($qty,$id){
$span=groovy\u菜单\u woocommerce\u迷你购物车\u计数器($qty);

return str_replace('我需要将代码应用于此doh,$output\u html.=''.groovy\u菜单\u woocommerce\u mini\u cart\u计数器($qty)“;@Agustin-只需更改变量名…我添加了额外的一行。好的,我相信这会起作用,但我太新手了,让我给你看完整的代码,我会编辑上面的帖子看看。它不起作用,因为你添加它的方式是错误的。现在我没有得到错误,但输出仍然没有id,我会将代码测试并保存你需要找到并编辑groovy\u menu\u woocommerce\u mini\u cart\u counter()函数,这是wordpress相关的问题,所以也许你应该问一下
$span = groovy_menu_woocommerce_mini_cart_counter($qty);
$spanWithId = "<span id='the-id'" . substr($span, 5, strlen($span));
$output_html .= $spanWithId;

echo "$spanWithId";
<span id='the-id' class="gm-cart-counter">2</span>
    global $woocommerce;

    $qty = 0;
    if ($tks == true) {
        $qty = $woocommerce->cart->get_cart_contents_count();
    }

    $cartIcon = 'fa fa-shopping-cart';

    $span = groovy_menu_woocommerce_mini_cart_counter($qty);
    $spanWithId = "<span id='the-id'" . substr($span, 5, strlen($span));

    $output_html .= '
                <div class="gm-minicart minicartmarie">
                    <a href="' . get_permalink( wc_get_page_id( 'cart' ) ) . '" class="gm-minicart-link minicartmarie">
                        <div class="gm-badge">
                            <i class="gm-icon ' . esc_attr( $cartIcon ) . '"></i>
                            ' . $spanWithId . '
                        </div>
                    </a>
                </div>
                ';
// create a wrapper function that injects the id
function menu_with_id($qty, $id){
  $span = groovy_menu_woocommerce_mini_cart_counter($qty);
  return str_replace('<span', "<span id='$id'", $span);
}

// then replace it
$output_html .= ' ' . menu_with_id($qty, $id) . ' ';