I have one attribute with the name tech_data and in this attribute I have the following values:

<p><a title="SDS" href="PDF/SDS/SDS.pdf" target="_blank">SDS</a> | <a title="Sheet" href="PDF/Specification/Sheet.pdf" target="_blank">Sheet</a> | <a class="caption" title="Brochure" href="/downloads/brochures/performance" target="_blank">Brochure</a> <hr />
<p> </p>
<p>Insulation Type: Insulator - Designed to be put directly on heat source to keep in</p>

I use the following code to split them in a separated li tag, I replace | with the li tag.

How I can remove everything after hr tag?

This is what I try:

<?php $attr = explode("|",$this->helper('Magento\Catalog\Helper\Output')->productAttribute($block, $block->getProduct()->getTechData(), 'tech_data')); 
    if(isset($attr)) {

    <ul class="custom-attribute">
        <?php foreach ($attr as $attrValue) { 
            <li class="button"><?php echo $attrValue; ?></li>

An Explode should do the trick here:

$value = explode("<hr />", $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block, $block->getProduct()->getTechData(), 'tech_data'));
$value = reset($value);
$attr = explode("|",$value);

The explode splits the string into a number of array items (depending on the number of HRs). The reset returns the first item in the array.

  • thank you, but how I can use the two functions on the same attribute? I mean I need to keep my first function to replace | with li tag too and to remove everything after hr on the same attribute? – Robert Jan 14 at 11:41
  • @Robert I've updated my answer to reflext this – Sander Mangel Jan 14 at 11:43
  • I have this error: Exception #0 (Exception): Warning: explode() expects parameter 2 to be string on this line: $value = reset(explode("<hr />",$attr)); – Robert Jan 14 at 12:01
  • @Robert ok this one should be right :) – Sander Mangel Jan 14 at 12:15
  • now I have this "Exception #0 (Exception): Notice: Only variables should be passed by reference in" on this line: $value = reset(explode("<hr />", $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block, $block->getProduct()->getTechData(), 'tech_data'))); – Robert Jan 14 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.