V
V
Veronika Stepanovna2017-05-30 21:35:29
Laravel
Veronika Stepanovna, 2017-05-30 21:35:29

How to replace internal links in the database with https?

There is a table with several thousand records (publications). It is necessary to check if there are links (internal) through in the body of the publication httpand replace this httpone with https.
I made a console command that gets all the id of publications and in a cycle foreachthrough the regular expression (I used AR) replaces the necessary one, after which I save the record.
Can it be done smarter?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RidgeA, 2017-05-30
@RidgeA

Well, at least do not use AR - this task is much easier to solve with a simple sql query - select the id and the text in which you want to replace.

A
Andrey Pavlenko, 2017-05-30
@Akdmeh

If you are careful and with a backup, you can use the MySQL REPLACE function:
https://stackoverflow.com/questions/5956993/mysql-...
https://dev.mysql.com/doc/refman/5.7/en/string- fun...
PS It won't work with WordPress, it has its own crutches!

K
Kirill Nesmeyanov, 2017-05-31
@SerafimArts

A small offtopic: It is advisable not to replace it with ` https://`, but simply replace all occurrences of ` http://` with `//`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question