3

I am using Magento 2.3.1

I have 8000 products which are migrated from Magento 1. The issue is that the
tags are added in short and long description in Magento 2. Please see below content for reference: enter image description here

This is how short description looks like in the front end. Below content is added in the product in admin:

This is the short description migrated from Magento 1<br><br>short description<br><br>• This is the point 1<br>• This is the point 2<br>• This is the point 3<br>• This is the point 4<br>• This is the point 5<br>•<b>This is the point 6</b>

I have used the below code:

<?php 
  $short_description = strip_tags( $short_description, 'li' );
  $short_description = "<ul><li>" . preg_replace( '/[\r\n]+/', '</li><li>', 
  $short_description ) . "</li></ul>";
  $short_description = str_replace('<li></li>', '', $short_description ); 
?>
<?= $short_description ?>

But the whole content is displayed in one <li> tag after implementing the above code.

Now I want to add each bullet points in <li> tags and also I want to remove <br> tag from the content as well. how can I do this?

  • 1
    why are you remove <ul> <li> & <br> tag? If you are using editor in admin then you can get save formate value in frontend using function. $block->filterOutputHtml('yout field_name') – Chirag Patel Jun 10 '19 at 8:28
1
<?php
$short_description= "This is the short description migrated from Magento 1<br><br>short description<br><br>• This is the point 1<br>• This is the point 2<br>• This is the point 3<br>• This is the point 4<br>• This is the point 5<br>•<b>This is the point 6</b>";
$strArray = explode('•',$short_description);
$newShortDescription = strip_tags($strArray[0]);
$newShortDescription .="<ul>";
for($i=1; $i<count($strArray);$i++){
    $newShortDescription .="<li>".strip_tags($strArray[$i])."</li>";
}
$newShortDescription .="</ul>";
?>
<?= $newShortDescription ?>
| improve this answer | |

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.