, Guest!
Already a Member? Login or Register.





Menu



Clients



Showcase



Rate FlexCMS

ScriptSearch.com Rating:

Hotscripts Rating
Excellent!
Very Good
Good
Fair
Poor



FlexCMS eNews

To subscribe to our enewsletter, please enter your email address in the box below and click the "Subscribe" button.


Note:  You may easily remove yourself from the newsletter list at any time by following the instructions included with every mailing.

LATEST DEVELOPMENT NEWS:  FlexCMS 2.5 has been released!!! Click here to read the official announcement!

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: 348
 
Search/Replace Old URLsApril 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;
 

Post Message 







All Contents, Code, Scripts and Technologies Copyright 2003-2007 FlexCMS.
All Rights Reserved. Software License Agreement

Processing Time: 0.10893 seconds.
 

Powered By FlexCMS
Powered By FlexCMS


Valid CSS!