Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6325375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:53:04+00:00 2026-05-24T16:53:04+00:00

I want to remove the domain extension .com from a string using preg_replace() ,

  • 0

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!! :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:53:05+00:00Added an answer on May 24, 2026 at 4:53 pm

    You do have to escape the dot but also regular expressions have to be passed in the form of /pattern/ that is between slashes

    preg_replace("/\.com/", "", $host); 
    

    Side note, there are better recommended ways to do this than using the almighty regular expressions. For example:

    $url = explode(".","http://static.facebook.com");   
    echo $url[1]; // facebook
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to remove domain name from my device list file. I have (device.marketing.company.com)
Hello I want to remove all the http://www.domain.com/?h from my mySQL database. ( the
I want remove "Language" querystring from my url. How can I do this? (using
I want to remove all special characters from a string. Allowed characters are A-Z
Here is my string: **tag:my.domain.com,2011-07-13:/895645783/posts/NHg5XdqFb5b/** I want to take the last section /NHg5XdqFb5b/ and
is it possible to remove Main Domain cookie from Sub Domain ?I am using
I need to remove the domain name from location.href using Javascript. I have links
I want to remove dots in acronyms but not in domain names in a
I want to remove a UIView from a superview and add it again at
I want to remove digits from a float to have a fixed number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.