Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:44:09+00:00 2026-06-10T07:44:09+00:00

I have html content in the post_content column. I want to search and replace

  • 0

I have html content in the post_content column.

I want to search and replace A with B but only the first time A appears in the record as it may appear more than once.

The below query would obviously replace all instances of A with B

UPDATE wp_posts SET post_content = REPLACE (post_content, 'A', 'B');

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:44:10+00:00Added an answer on June 10, 2026 at 7:44 am

    This should actually be what you want in MySQL:

    UPDATE wp_post
    SET post_content = CONCAT(REPLACE(LEFT(post_content, INSTR(post_content, 'A')), 'A', 'B'), SUBSTRING(post_content, INSTR(post_content, 'A') + 1));
    

    It’s slightly more complicated than my earlier answer – You need to find the first instance of the ‘A’ (using the INSTR function), then use LEFT in combination with REPLACE to replace just that instance, than use SUBSTRING and INSTR to find that same ‘A’ you’re replacing and CONCAT it with the previous string.

    See my test below:

    SET @string = 'this is A string with A replace and An Answer';
    SELECT @string as actual_string
    , CONCAT(REPLACE(LEFT(@string, INSTR(@string, 'A')), 'A', 'B'), SUBSTRING(@string, INSTR(@string, 'A') + 1)) as new_string;
    

    Produces:

    actual_string                                  new_string
    ---------------------------------------------  ---------------------------------------------
    this is A string with A replace and An Answer  this is B string with A replace and An Answer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html content: <p>My name is <a href=way2project>way2project</a></p> Now I want
I have a JSON file which contains HTML content. I want to load it
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I have HTML Content which was being displayed in a UITextView . The next
If I have HTML content in a variable like so: var data = <div
Suppose we have this html content, and we are willing to get Content1, Content2,..
I am parsing an html content and have output on my screen. This website
I have an asp.net UserControl that writes HTML content from a SharePoint list to
I have seen some mails which has HTML content embedded in them. The content
I have a model which defines a property with either markdown or html content.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.