MySQL String Replacement
This question addresses the need to modify specific text within a MySQL database column. The task involves replacing instances of the word "updates" with "news" in URLs stored in a column.
To achieve this, a MySQL script can be employed to execute a REPLACE function on the affected column. The script suggested in the provided answer is designed to accomplish the desired modification:
UPDATE your_table SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/') WHERE your_field LIKE '%articles/updates/%'
This script effectively searches for occurrences of the string "articles/updates/" within the "your_field" column and replaces them with "articles/news/". The WHERE clause ensures that only rows containing the specified string are modified.
For instance, a URL originally stored as "http://www.example.com/articles/updates/43" will be transformed into "http://www.example.com/articles/news/43". This change is reflected across all rows in the table that match the search criteria.
The above is the detailed content of How to Replace 'updates' with 'news' in MySQL URLs?. For more information, please follow other related articles on the PHP Chinese website!