Jump to content

[SOLVED] Cant seem to get preg_replace to work!


emma57573

Recommended Posts

What Im trying to do is if somebody types in www.theirdomain

 

It removes the www. part and they are just left with theirdomain

 

 

MY Code

$domain=$_REQUEST["domain"];
$patterns[0] = '/www./';
$replacements[0] = '';
preg_replace($patterns, $replacements, $domain);

 

It outputs www.theirdomain  so does not remove the www. bit as I want it to? Any ideas where I am going wrong?

Ive now tried taking out the slashes and got this error

 

[phpBB Debug] PHP Notice: in file /home/misimeuk/public_html/store_infotest.php on line 31: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash

 

Does that mean I cant use preg_replace with a '.'  :-\

Ive fixed this with the following:


$domain=$_REQUEST["domain"];


$patterns = "www.";
$replacements = "";
$domain = str_replace($patterns, $replacements, $domain);


 

Sometimes just writing out te question helps you think with a clear head  ;D

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.