Easily updating links in forums, wikis and sites

Have questions? We've got answers. Test your signatures here, but please keep all sig tests in the sig test topic.

Moderators:Best First, spiderfrommars, IronHide

User avatar
Denyer
Over Pompous Autobot Commander
Posts:2155
Joined:Tue Oct 17, 2000 11:00 pm
::Yesterday's model
Contact:
Easily updating links in forums, wikis and sites

Post by Denyer » Sun Sep 13, 2009 2:29 pm

Details will vary slightly depending on the structure of your web application, so here's a generic version using MySQL:

Code: Select all

UPDATE nameoftable SET nameoftextfield = replace(nameoftextfield ,'[url]http://transfans.net','[url]http://transfans.co.uk');
UPDATE nameoftable SET nameoftextfield = replace(nameoftextfield ,'[url=http://transfans.net','[url=http://transfans.co.uk');
In vBulletin, as an example, it's probably the "post" table and the "pagetext" field. Since vB caches the contents of posts for speed, you'd also want to run 'Rebuild Post Cache' under Admin CP > Maintenance > Update Counters, and other forum systems may have similar functionality.

It's also possible to change lots of files easily if you have a flat-file wiki (or other situations where lots of files stored together want updating) -- this is one way of doing so using PHP:

Code: Select all

<?
$files=glob("*.txt");
foreach ($files as $file) {
$data=file_get_contents($file); echo "Opening ".$file;
$edit=str_replace("transfans.net","transfans.co.uk",$data);
if ($data!=$edit) { file_put_contents($file,$edit); echo " ... changes made<br>"; }
echo " ... done<br>";
}
?> 
Any questions, ask away. I'm not a guru at scripting either of the above technologies, but this isn't a complicated topic.

Post Reply