我需要通过echo在元数据之间留出空间



也许有人可以帮我解决这个问题。

我有这个代码:

<?php if( $showPmeta ): ?>
<span class="xoo-wsc-pmeta"><?php echo  $product_meta;  ?></span>
<?php endif; ?>   

我的结果是:

meta1meta2meta3

如何在这些元数据之间留出空间?

提前谢谢。

这是从中获取字符串的函数。

foreach ( $cart as $cart_item_key => $cart_item ) {
$bundleData = xoo_wsc_cart()->is_bundle_item( $cart_item );
if( $_product->get_type() === 'variation' ){
if( $pnameVariation === "no" ){
$product_name = $_product->get_title();
$cart_item['data']->set_name( $_product->get_title() );
}
}
$product_meta       = wc_get_formatted_cart_item_data( $cart_item );
$cart_item_args = array(
'product_meta'      => $product_meta,
);

请展示您是如何获得$product_meta的。我怀疑这是一个数组,因为echo()'ng数组会导致:

PHP Notice:  Array to string conversion in php shell code on line 1
Array

我们不仅会得到Notice,还会只得到Array,而不是串联的数组值。

如果$product_meta是一个简单的字符串数组,并且您正在调用一个函数";转换";则可能使用implode()并使用空格(""(作为字符串;"胶水";,例如$product_meta = implode(' ', $product_meta)

此外,除非我们确定$product_meta只包含字母数字字符,否则让它在echo()上经过htmlspecialchars(),以确保它不会破坏您的HTML,例如echo htmlspecialcars($product_meta)

最新更新