查找,隔离,重构en替换数据库中的字符串

时间:2021-08-14 19:25:48

I have a very practical question. I have got about 400 articles in my database and in those articles i have links to other articles. During conversion the links were broke. We inserted new menu-link items manually in our CMS. I want to make a script that looks for an (article)id and replace the menu-item id within the internal link for a new menu-item id.

我有一个非常实际的问题。我的数据库中有大约400篇文章,在这些文章中我有其他文章的链接。在转换过程中,链接被破坏了。我们在CMS中手动插入了新的菜单链接项。我想创建一个查找(文章)ID的脚本,并替换内部链接中的菜单项ID以获取新的菜单项ID。

For example: this is the old internal link in table twsf_content, column introtext:

例如:这是表twsf_content,列introtext中的旧内部链接:

index.php?option=com_content&view=article&id=140&Itemid=613&ldquo;v.d.Hermels Hoeve&rdquo;</a>

this must be the new link in table twsf_content:

这必须是表twsf_content中的新链接:

index.php?option=com_content&view=article&id=140&Itemid=397&ldquo;v.d.Hermels Hoeve&rdquo;</a>

the only thing that changed is the Itemid (397 in stead of 613).

唯一改变的是Itemid(397而不是613)。

We can find article&id (in this case 140) in another table (twsf_menu, column link) and determine what Itemid must be: 397 (column Id) in stead of 613.

我们可以在另一个表(twsf_menu,列链接)中找到article&id(在本例中为140)并确定Itemid必须是什么:397(列Id)而不是613。

There can be more links in one article.

一篇文章中可以有更多链接。

In short: we want to find all links in all articles and replace the Itemid for the new Itemid.

简而言之:我们希望找到所有文章中的所有链接,并替换新Itemid的Itemid。

Can somebody give me the code to do this?

有人可以给我代码吗?

Thanks in advance!

提前致谢!

1 个解决方案

#1


Extract the stuff to a CSV file, work on that with sed and awk and load it back to the database would be my approach. MySQL isn't good in recursively working with regex and this looks like one-off job.

将内容解压缩到CSV文件,使用sed和awk处理它并将其加载回数据库将是我的方法。 MySQL在递归使用正则表达式方面表现不佳,这看起来像是一次性的工作。

#1


Extract the stuff to a CSV file, work on that with sed and awk and load it back to the database would be my approach. MySQL isn't good in recursively working with regex and this looks like one-off job.

将内容解压缩到CSV文件,使用sed和awk处理它并将其加载回数据库将是我的方法。 MySQL在递归使用正则表达式方面表现不佳,这看起来像是一次性的工作。