|
|
Due to the volume of spam happening on our forums, posting is now restricted to verified members only. If you're not verified, drop us a note with your username.
|
|
Home > FlexCMS Support Forum > User Help > Code Snippets > Search/Replace Old URLs
FlexCMS Support Forum
Search/Replace Old URLs Started April 25, 2005 @ 11:21pm by DCSun
|
Post Message |
DCSun Administrator
Posts: 625 |
|
|
Search/Replace Old URLs | April 25, 2005 @ 11:21pm | The script below can be pasted into a new php-enabled page, update the first two lines to match your site, then run, and that will replace any of the old urls in the pages, blocks, and forum messages. As always, you should backup the database before running this just in case.
Code
$StringToFind = 'yourdomain.com/flex'; $ReplacementString = 'yourdomain.com';
// pages $query = "select * from `".$Settings['DBPrefix']."core-Pages` where PageLink!='".$Arguments2."'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { if (strpos($row['PageContents'],$StringToFind) !== false) { $row['PageContents'] = str_replace($StringToFind,$ReplacementString,$row['PageContents']); $PageReplacements++; $query2 = "update `".$Settings['DBPrefix']."core-Pages` set PageContents='".addslashes($row['PageContents'])."' where RecordNumber='".$row['RecordNumber']."' limit 1"; $result2 = mysql_query($query2) or die (mysql_error()); } }
// blocks $query = "select * from `".$Settings['DBPrefix']."core-Blocks`"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { if (strpos($row['BlockContents'],$StringToFind) !== false) { $row['BlockContents'] = str_replace($StringToFind,$ReplacementString,$row['BlockContents']); $BlockReplacements++; $query2 = "update `".$Settings['DBPrefix']."core-Blocks` set BlockContents='".addslashes($row['BlockContents'])."' where RecordNumber='".$row['RecordNumber']."' limit 1"; $result2 = mysql_query($query2) or die (mysql_error()); } }
// forum messages $query = "select * from `".$Settings['DBPrefix']."mb-Messages`"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { if (strpos($row['Message'],$StringToFind) !== false) { $row['Message'] = str_replace($StringToFind,$ReplacementString,$row['Message']); $ForumReplacements++; $query2 = "update `".$Settings['DBPrefix']."mb-Messages` set Message='".addslashes($row['Message'])."' where RecordNumber='".$row['RecordNumber']."' limit 1"; $result2 = mysql_query($query2) or die (mysql_error()); } }
print '<br><b>Search and Replace Complete.<br><br>Replacements:<br></b>Pages: '.$PageReplacements.'<br>Blocks: '.$BlockReplacements.'<br>Forum Posts: '.$ForumReplacements; |
|
|
FlexCMS v3.2 Has Been Released! |
|
|
|
|
|
|
|
|
|
| MEMBERS
|
|
|