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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -