Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Search   replace mySQL data
  2. Text Text Text Text Text
  3. [swordfish filename=code.bas]
  4. code code code
  5. 123
  6. code code[/swordfish]
  7. Text Text Text Text Text
  8.        
  9. Text Text Text Text Text
  10. [code]
  11. code code code
  12. 123
  13. code code[/code]
  14. Text Text Text Text Text
  15.        
  16. $regexp = '/[(/)?swordfish[^]]*]/';
  17.  
  18. $push = 'REPLACE whatever_table (id, post_text)
  19.           VALUES';
  20.  
  21. $pull = 'SELECT id, post_text
  22.            FROM whatever_table
  23.           WHERE whatever = condition';
  24.  
  25. if ( $result = $mysqli->query($pull) ) {
  26.     while ( $row = $result->fetch_assoc() ) {
  27.         $row['post_text'] = preg_replace($regexp, '[$1code]', $row['post_text']);
  28.  
  29.         $push .= sprintf(
  30.             ' ("%s", "%s"),',
  31.             $mysqli->real_escape_string($row['id']),
  32.             $mysqli->real_escape_string($row['post_text'])
  33.         );
  34.     }
  35.  
  36.     $result->free();
  37. }
  38.  
  39. $mysqli->query(rtrim($push, ','));