0

Trying to use ChristoKiwi's https://stackoverflow.com/questions/19356897/removing-links-from-posts-in-wordpress-using-query/61652078#61652078 approach for deleting links in Joomla articles, but having issues with this example:

    <p>
   <img
      class="responsive caption"
      style="margin-right: 10px; float: left;"
      src="images/stories/ds/Specials/Mikrosystemtechnik/2019/rohm0119.jpg"
      alt="rohm0119"
   /><a
      dir="ltr"
      title="Rohm"
      href="https://www.rohm.de/"
      target="_blank"
      rel="noopener"
      >Rohm </a
   >kündigt mit dem BM14270MUV-LB einen der kleinsten berührungslosen
   Stromsensoren der Industrie an. Der neue Baustein verbraucht nur minimal
   Strom und ist mit 3,5 x 3,5 x 1,0 mm sehr kompakt.&nbsp;Damit eignet er sich
   für Industrieanlagen und Verbrauchergeräte, die Betriebsbedingungen über den
   Stromfluss erfassen wie batteriebetriebene Drohnen, Solaranlagen und Server
   in Rechenzentren.
</p>

The query

UPDATE jos_content SET jos_content.introtext = REPLACE(jos_content.introtext, substring_index( substring_index(jos_content.introtext, 'title="', -1), '"', 1),'')

deletes not only the text within the "title" but also the word "Rohm" after the link.

How to delete the entire link with all the attributes completely?

  • Welcome to JSE, Jens, please take our tour. I see that when you registered here, that you did not associate your registration with your pre-existing Stack Exchange account (your Stack Overflow acct); please read about merging your accts. Please add a link to your question that references where "ChristoKiwi's approach" is on the web. I feel like hacking at introtext data via SUBSTRING_INDEX() surgery is a suboptimal approach. What does your template look like? – mickmackusa May 7 at 22:16
  • @mickmackusa Have added the link to ChristoKiwi. With this website we're using "Notio" a Rockettheme template and the JCE editor. Have a look here: developmentscout.com – user13488789 May 7 at 23:22
1

It appears on review of Christo Kiwi's solution that it only works with a link which has an identical part of which you wish to remove.

Based on your example, I suspect that your link is a variable and so you may need to take a slightly different approach.

  1. You first need to identify the start position and end position of the string component in the intro text that you wish to remove.
  2. Once you have found the start and end positions (which you can check using a select statement) then you can build your update/replace based on that. For example, you may need to find the position of <a dir and then the position of the next > after that and use that in your replace string.

I would definitely start by creating a SELECT query to make sure that you are correctly getting the article ID and the string part that you wish to replace and then build that into your update query.

In my particular case, I was looking for multiple links of the same type in intro text so I had to work out the position of the first start and end, then the second start and end, then the third start and end and replace all three.

Here is a snippet of code which may help you - I've used LOCATE() and SUBSTRING() to first check that the data I was going to replace was what I was expecting, then I built that into my replace function.

SELECT
    id,
    introtext,
    SUBSTRING(introtext, LOCATE('<li><a href="index.php?option=com_docman', introtext), 4 + LOCATE('/li>', introtext, LOCATE('<li><a href="index.php?option=com_docman', introtext)) - LOCATE('<li><a href="index.php?option=com_docman', introtext)) AS pos1text
FROM `d8bk2_content` 
WHERE id >395
  AND introtext LIKE '%<li><a href="index.php?option=com_docman%'

In your case, you would LOCATE('<a dir') and then the next closing tag etc.

| improve this answer | |
  • Thank you very much @sirobertson for your detailed answer. In the meantime I tried to learn and modify your snippet for my cases which worked, but noticed also that there are so much possibilities to "create" an external link. Therefore I decided to deleted them "manually" via the JCE editor and eliminate simultaneously some unnecessary content as well. – user13488789 May 10 at 16:35
  • @user13488789 if you decided not to use any of the answers provided, please post why and how you resolved your issue as a new answer on this page. Then you may accept your own answer. When answering (any question), please be generous with your explanation so that future researchers can learn from your insights. – mickmackusa May 16 at 4:47
1

As an alternative, you could have opened up your template and used php's native strip_tags function which allows a list of exceptions, so...

echo strip_tags($this->item->introtext, '<img><p><listofallowedelements>');
| improve this answer | |
  • Thank you so much guys for all your answers. I really appreciate it!. After spending hours on figuring out how to create a query to eliminate the different links, which changes a lot within 10 years of Joomla, the result was that there are so much possibilities. This ended up that the content table was altered so that the text result at the frontend shows some highlighted text without a link, but with a different color. – user13488789 May 18 at 13:05
  • May be due to the combination of the JCE editor. I don't know. Additional I had to delete some other text so that I decided to make all these changes manually. Yes, I gave up. That's not really funny because of approx. 10.000 articles but less time towards to try to deal with all the "destroyed" content tables ;-) – user13488789 May 18 at 13:05

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.