tfw2005
01-30-2006, 05:08 PM
Help with a preg_replace call in includes/functions_newpost.php
I currently have a simple preg_replace function working, not in the board system.
I would like to apply it to all new posts before they are inserted into the DB.
This is the original preg_replace
<?php
$string = "http://subdomain1.domain1.com/";
$find = "/http:\/\/subdomain1\.domain1\.com\//";
$replace = "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";
print preg_replace($find, $replace, $string);
?>
I would like to apply that logic to any instance of http://subdomain1.domain1.com/ that is present in a users post, then enter it into the DB.
I tried the following to no avail in includes/function_newpost.php
// ### POST NEW POST ###
$string = "$post['message']";
$find = "/http:\/\/subdomain1\.domain1\.com\//";
$replace = "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";
$post['message'] = preg_replace($find, $replace, $string);
$DB_site->query("
INSERT INTO " . TABLE_PREFIX . "post
............................... etc
Any idea how to get that to apply? I saw an amazon affiliates hack that did it, but couldnt get it to work.
Would also be great if the logic could make it so that the link shown is the original link, while the acutal url= part has the rewritten code. For asthetic purposes, because these links can get rather long.
Thanks for the help.
I currently have a simple preg_replace function working, not in the board system.
I would like to apply it to all new posts before they are inserted into the DB.
This is the original preg_replace
<?php
$string = "http://subdomain1.domain1.com/";
$find = "/http:\/\/subdomain1\.domain1\.com\//";
$replace = "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";
print preg_replace($find, $replace, $string);
?>
I would like to apply that logic to any instance of http://subdomain1.domain1.com/ that is present in a users post, then enter it into the DB.
I tried the following to no avail in includes/function_newpost.php
// ### POST NEW POST ###
$string = "$post['message']";
$find = "/http:\/\/subdomain1\.domain1\.com\//";
$replace = "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";
$post['message'] = preg_replace($find, $replace, $string);
$DB_site->query("
INSERT INTO " . TABLE_PREFIX . "post
............................... etc
Any idea how to get that to apply? I saw an amazon affiliates hack that did it, but couldnt get it to work.
Would also be great if the logic could make it so that the link shown is the original link, while the acutal url= part has the rewritten code. For asthetic purposes, because these links can get rather long.
Thanks for the help.