1

I have a Magento site in which each product has an anchor tag like <a href="link">Content</a> in their descrption field.

Now I want to remove this anchor tag along with it's content inside the tag, but keep the rest of description as it is.

Right now a sample description is like below:

<ul>
    <li>Cylinder head has been assembled to OEM specifications with using all new components like Cam shaft, valves and/or springs, buckets, shims etc. where applicable.</li>
    <li>
        <a href="http://sampledomain.com/media/wysiwyg/folder/file.pdf">All heads we supply pass through 24 points of quality check program.</a>
    </li>
    <li>Warranty: 1 year or 20,000 Kms factory warranty.</li>
    <li>
        <b>Kit Includes:</b>
    </li>
    <li>Fully assembled cylinder head</li>
    <li>VRS (Vehicle regrind set)</li>
    <li>Head gaskets (thickest grade)</li>
    <li>Head bolts</li>
    <li>Warranty card</li>
</ul>

Now I want it show up like below:

<ul>
    <li>Cylinder head has been assembled to OEM specifications with using all new components like Cam shaft, valves and/or springs, buckets, shims etc. where applicable.</li>
    <li>
    </li>
    <li>Warranty: 1 year or 20,000 Kms factory warranty.</li>
    <li>
        <b>Kit Includes:</b>
    </li>
    <li>Fully assembled cylinder head</li>
    <li>VRS (Vehicle regrind set)</li>
    <li>Head gaskets (thickest grade)</li>
    <li>Head bolts</li>
    <li>Warranty card</li>
</ul>

How can I do this with an Update query ?

4
  • does it contain only one anchor tags or multiple for each product? Commented May 24, 2016 at 6:34
  • show a real sample and the result you need .. Commented May 24, 2016 at 6:35
  • It has only one anchor tag, per product description. Updating my question to add description. Commented May 24, 2016 at 6:39
  • Some tasks are best left for application code, not SQL. Commented May 29, 2016 at 5:16

1 Answer 1

1

This will does the job ..!

UPDATE your_table_name  
set description = 
concat
(
substring_index(description, '<a',1), 
substring_index(description, '</a>',-1)
);
Sign up to request clarification or add additional context in comments.

2 Comments

But different products has different description that's why I thought regex would be better.
Your answer is good for selecting records, can you also add query for updating to this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.