I want to remove the domain extension .com from a string using preg_replace(), so for example, if the subject parameter is facebook.com, .com will be erased from the string.
I thought this would work, preg_replace(".com", "", $host);
Unfortunately it returned the error:Warning: preg_replace() [function.preg-replace]: No ending delimiter '.' found in.
I then attempted to escape the period with a backslash (thinking this was the problem), which returned:
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Any comments, answers or information would be greatly appreciated!! :).
You do have to escape the dot but also regular expressions have to be passed in the form of
/pattern/that is between slashesSide note, there are better recommended ways to do this than using the almighty regular expressions. For example: