Line break
-
Dear support staff,
Is it possible to search & replace a string in posts with a line break in it?
For example I would like to change this:
ABCD
FGHIto this:
ABCD
JKLMThank you.
-
WORDPRESS: GUIDE FOR SEARCH AND REPLACE text in posts with line break or any special characters (brackets, round brackets, parentheses, quotation marks etc.)
You dont need any new plugins or PHP scripts for this operation but PHPMyAdmin access. If you don’t have CPanel account or direct PHPMyAdmin access for your WordPress installation contact your webhosting administrator to get one.
Part I. – Getting the source (code and/or text) to be replaced
1) Download an SQL backup of your database (Use your existing Search and Replace plugin: WordPress Tools menu, Search & Replace, “Backup database” tab at the top, and press Create SQL file. When finished download it.)
2) Open the downloaded file with a Hex Editor, Hex Viewer or Notepad++.
3) Find the string in this source you want to change. Take care of the special characters and accents because they can be UTF-8 encoded so you possibly won’t find them the same way as it displays in a post or on a page.
Tip: Look for alphanumerical characters only. That means look for just parts of your whole content to be replaced or at least strings that are close to it.
4) You will see that line breaks are stored as \r\n in the WordPress database. Select and COPY to clipboard the entire content you would like to change.
5) Paste the clipboard into a new notepad window to have the original content. Press Enter twice. Now paste the clipboard again and precisely modify this second content as your prefer. After that you can compare the two parts.
6) Press Enter twice after the second content then copy and paste the line below to the notepad window too as a 3rd section:UPDATE wp_posts SET post_content = replace(post_content, ‘OLDCONTENT’, ‘NEWCONTENT’)
7) Now copy the 1st section (original part) to OLDCONTENT and the 2nd section (modified part) to NEWCONTENT by replacing these words and keeping the apostrophes. (See example later.)
It’s not a problem if the texts inside the apostrophes are very long and contain quotation marks and/or brackets () ” [] {} <> etc.
8) Copy this newly created command line in the 3rd section to the clipboard.Part II. – Replacing the source (code and/or text) to the modified version.
1) Login to your CPanel account if you have one.
2) Find PHPMyAdmin icon and click on it.
3) On the left panel click once on the name of the WordPress database you need to edit. (For example: johndoe_websitename)
4) In the opening list select wp_posts. (Table)
5) Now look for the middle panel and press SQL button on the top menu toolbar.
6) Delete the first line (eg. SELECT * FROMwp_posts
WHERE 1) so that the box is empty.
7) Paste your search and replace command line you created in the previous step here: UPDATE wp_posts SET post_content = replace(post_content, ‘HERE IS YOUR OLD CONTENT’, ‘HERE IS YOUR NEW CONTENT’)
8) Click on “Simulate query” button at the right.
9) Nothing will be changed or written to the database this time. You can see in advance if you will or won’t have any hits.
10) If you have positive hits you can preview the list of fields: press CTRL and click on the number after “Matching lines” to open the results window in a new browser tab. (You won’t be able to see the exact place of the matches.)
11) Press “Go” button at the right to actually change the old content to the new one. You will get a green feedback about the modifications in a second.Example with the 1-3 sections:
Name:</td>\r\n<td class=\”A1\”>John Doe
OLD text copied from the SQL source. \r\n means a line break.Name:</td>\r\n<td class=\”B1\”>Jane Doe
NEW text modified on demandUPDATE wp_posts SET post_content = replace(post_content, ‘Name:</td>\r\n<td class=\”A1\”>John Doe’, ‘Name:</td>\r\n<td class=\”B1\”>Jane Doe’)
Command line after inserting the OLD and NEW parts.- This reply was modified 6 years, 5 months ago by uridium75.
- The topic ‘Line break’ is closed to new replies.