Home > Database > Mysql Tutorial > How to Replace a String within URLs in MySQL?

How to Replace a String within URLs in MySQL?

Susan Sarandon
Release: 2025-01-03 04:53:40
Original
735 people have browsed it

How to Replace a String within URLs in MySQL?

MySQL String Replacement Solution for URL Modification

A database table contains a column of URLs with a pattern like "http://www.example.com/articles/updates/XXX," and the need is to replace the term "updates" with "news" in these URLs.

To achieve this task through a MySQL script, the following query can be executed:

UPDATE your_table
SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/')
WHERE your_field LIKE '%articles/updates/%'
Copy after login

Here, "your_table" represents the relevant table, "your_field" indicates the URL column, and the LIKE clause ensures that only URLs containing "updates" are updated.

As a result, URLs like "http://www.example.com/articles/updates/43" will be transformed into "http://www.example.com/articles/news/43."

For further information on text replacement in MySQL, refer to the "Find and Replace Text" article at http://www.electrictoolbox.com/mysql-find-replace-text/.

The above is the detailed content of How to Replace a String within URLs in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template