Z
Z
zugo2014-12-14 18:02:18
PHP
zugo, 2014-12-14 18:02:18

How to find and replace blocks of text (HTML code) in a MySQL database?

There is a shitty WordPress site with about ~900 pages. Some of them have an HTML form (right in the body of the page). You need to replace it with the shortcode of the Contact Forms 7 plugin.
A normal request like

UPDATE wp_posts
SET post_content = REPLACE(post_content, 'найти', 'заменить на')
WHERE post_content LIKE '%найти%';

of course, it doesn't work, because these are blocks of HTML code with line breaks, formatting, etc. Is it possible to do something about this? Regular expressions (I don't know them) can help?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yakhnenko, 2014-12-14
@ayahnenko

1. sql - select all pages from database
2. php foreach is all
3. php -regular check for the presence of a form
4. php -regular to replace
5. sql - update record in database

F
FanatPHP, 2014-12-14
@FanatPHP

Weird. And what - formatting and line breaks in all forms are different? right here in each-each form is unique?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question