2014-01-22 67 views
0

使用WooCommerce for Wordpress我創建了產品屬性,我有一行值,我使用;作爲分隔線將其分割爲<td>,這種方法可行,但問題在於Wordpress保留將<p>標籤添加到輸出。PHP WooCommerce從字符串中刪除p標記

查看輸出HTML似乎包裹第一$applies[0]<p></p>然後$applies[3]具有後<p></p>。當我更願意從字符串中刪除所有<p>

我試過echo str_replace("<p>","",$apply);$applied = preg_replace('#<p[^>]*>(\s|&nbsp;?)*</p>#', '', $apply);但仍然沒有運氣。

PHP

<tr class="<?php if (($alt = $alt * -1) == 1) echo 'alt'; ?>"> 
<th><?php echo $woocommerce->attribute_label($attribute['name']); ?></th> 
<td><?php 
    if ($attribute['is_taxonomy']) { 
     $values = woocommerce_get_product_terms($product->id, $attribute['name'], 'names'); 
     echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values); 
    } else { 
     //Convert pipes to commas and display values 
     $values = array_map('trim', explode('|', $attribute['value'])); 
     $apply = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values); 
     $applies = explode(";", $apply); 
     echo $applies[0]."</td><td>"; 
     if ($applies[2] != ''){ 
      echo "<font style='text-decoration:line-through'>".$applies[1]."</font></td><td>"; 
     } else { 
      echo $applies[1]."</td><td>"; 
     } 
     echo $applies[2]."</td><td>"; 
      $applies3 = str_replace(' ', '', $applies[3]); 
      $applies3 = str_replace('<p></p>', '', $applies3); 
     echo $applies[3]; 
    } 
     ?></td> 
    </tr> 

輸出HTML

<tr class=""> 
    <th>Container</th> 
    <td><p>W2300 x D1030 x H940mm</p></td><td> £19953</td><td></td><td> in stock<p></p></td> 
</tr> 

回答

1

更改

$apply = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);

$apply = apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);

通過從該行刪除wpautop()它將刪除<p>標籤。