php - Update only part of the column - multiple rows -
as part of migrating website https, i'm changing http urls in blog articles relative urls.
current data in articles
table:
╔════╦═══════════════════════════════════════════════════════════════╗ ║ id ║ content ║ ╠════╬═══════════════════════════════════════════════════════════════╣ ║ 1 ║ lorem ipsum <a href='http://www.example.com/'>link</a> etc ║ ║ 2 ║ see more <a href='http://www.example.com/page.html'>here</a> ║ ║ 3 ║ bla bla bla <img src='http://www.example.com/image.jpg' /> ║ ╚════╩═══════════════════════════════════════════════════════════════╝
desired output relative urls:
╔════╦═══════════════════════════════════════════════════════════════╗ ║ id ║ content ║ ╠════╬═══════════════════════════════════════════════════════════════╣ ║ 1 ║ lorem ipsum <a href='//www.example.com/'>link</a> etc ║ ║ 2 ║ see more <a href='//www.example.com/page.html'>here</a> ║ ║ 3 ║ bla bla bla <img src='//www.example.com/image.jpg' /> ║ ╚════╩═══════════════════════════════════════════════════════════════╝
notes:
- there's few hundred rows these hardcoded links.
- each row can contain more links.
i thinking going on each row, changing links regex , updating row.
$query = $db->query("select id,content articles content '%http://www.example.com%'"); while ( $row = $query->fetch_row() ) { $updatedcontent = /* regex remove "http:" part */ $db->query("update articles set content = ..."); }
but i'd learn new thing, question is:
is there other way? possibly regex in postgresql allow update part of column , not waste resources on going on hundreds of rows thousands of characters in each of them?
you don't need php this. can done via simple database query:
update articles set content = replace(content, 'http:', '');
Comments
Post a Comment