Hi

I have imported a number (500+) posts into Wordpress from another CMS (Expression Engine).

On a number of posts I have a problem with the way paragraphs are being displayed and I can trace this back to the post data that has been copied across.

For example, when the post html is a follows:

<p>'Insolvency' doesn't always mean bankruptcy, though. There
are various forms of insolvency that can help people in different situations,
from IVAs (Individual Voluntary Arrangements) and DROs (Debt Relief Orders) to
Protected Trust Deeds.</p>

is is displayed as

Insolvency’ doesn’t always mean bankruptcy, though. There
are various forms of insolvency that can help people in different situations,
from IVAs (Individual Voluntary Arrangements) and DROs (Debt Relief Orders) to
Protected Trust Deeds.

What should happen is that this should appear as one paragraph that wraps depending on the width of the column that is available, but because of the line breaks after the words 'There' and 'situations,' the paragraph is broken up. Is there an SQL solution to run on the wp_posts table - column post_content to remove these line breaks from within paragraphs i.e. where there is a <p> and </p> present?

A second similar issue arises where there is no openng <p> or closing </> but the same line breaks e.g.

And there are other forms of assistance that can help people
steer clear of the kind of situation where they'd need to think about entering
insolvency.

In this case this should appear as one paragraph but the line breaks after 'people' and 'entering' cause it be broken up onto new lines. Again, if there a piece of SQL that could correct this?

I really don't want to have to go through any manually edit each post of I can avoid it.

Many thanks in advance

Regards
Mark

Recommended Answers

All 2 Replies

MySQL does not come with regular expression search/replace functions. Therefore you will either have to write a MySQL function which does the following:
- find a <p> in the text;
- find the matching </p> thereafter;
- replace all line breaks in between by spaces.
Or you write a piece of PHP code (or some other script language) which does the same, but with the help of regular expressions.
Or you export the table in SQL format, load it into an editor like EditPad++ and use the RegEx functions of the editor to replace the line breaks. Afterwards you import it into your table again.

Thank you - I have used EditPlus and replaced instances of \r\n with a space and it seems to have worked. Don't know why I didn't think of that myself.

Regards
Mark

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.