I manage to fix my on code:
if (!$urlIsValid) {
die("Error: The requested URL was disallowed by the server administrator.");
}
$response = makeRequest($url);
$rawResponseHeaders = $response["headers"];
$responseBody = $response["body"];
$responseInfo = $response["responseInfo"];
//SET THE BANNED WORDS.
$banned_words = array("Prick","****","bull****","****","asshole");
//SUBSTITUTE THE BANNED WORDS ON PROXIED PAGE (CONTENT FILTERING).
if($responseInfo['http_code'] == '200' )
{
$regex = '/\b'; // The beginning of the regex string syntax
$regex .= implode('\b|\b', $banned_words); // joins all the banned words to the string with correct regex syntax
$regex .= '\b/i'; // Adds ending to regex syntax. Final i makes it case insensitive
$substitute = '****';
$responseBody = preg_replace($regex, $substitute, $responseBody);
}
I changed this:
$url = preg_replace($regex, $substitute, $response);
to this:
$responseBody = preg_replace($regex, $substitute, $responseBody);