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 3229550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:49:25+00:00 2026-05-17T16:49:25+00:00

I would like to do the following, preferably with PHP: Remove an entire word

  • 0

I would like to do the following, preferably with PHP:

Remove an entire word if a part of the word contains a specific string. This should be case insensitive and work multiple times, e.g. on a large text.

Pseudo-code:

match = "www."
lots_of_random_text = "... hello and welcome to www.stackoverflow.com! blah blah"
result = magic_function(lots_of_random_text, "www.")

result should now equal to: "... hello and welcome to blah blah".

How would I do this the most efficient way?

  • 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-17T16:49:26+00:00Added an answer on May 17, 2026 at 4:49 pm

    It seems that a regular expression would suit this task. Check out the docs for preg_match to start with, or the main PCRE docs for a complete overview.

    php> $text="hello and welcome to www.stackoverflow.com snout pickle and while you're here, check out a unicorn at www.unicornmagicfairywonderland.net!";
    php> $cleaned_text=preg_replace('#www\.[\w\d]+\.(com|net|org)#','',$text);
    php> echo $cleaned_text;    
    hello and welcome to  snout pickle and while you're here, check out a unicorn at !
    

    The key part is the ‘#www.[\w\d]+.(com|net|org)#’. That means match any string that starts with http://www.,has any number of word characters or digits, and ends with .com, .net or .org.

    If you’re trying to replace any URL, the expression is going to be much more complex than this, so be warned this is incomplete. You’d want to make sure it matches words that start with http://, have no www. or have a different subdomain, and end with other domains like .co.uk or .edu, right?

    Regular expressions are in general, complex and tough to get right. You may find http://www.regular-expressions.info helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to do the following but I don't think this will work:
I would like to do something like the following: class String def fancy_thing appendix
I would like to do something like the following but can't seem to get
I would like to do something like the following: def add(a, b): #some code
I would like to be able to do somthing like the following: //non-generic var
I would like to add the following MIME type to a site run by
I would like to monitor the following system information in Java: Current CPU usage**
I would like to redirect the following as an example: A.olddomain.com.au/blah.html > A.newdomain.com/blah.html B.olddomain.com.au/blah.html
I would like to do the following: $find = "start (.*) end"; $replace =
I would like to do the following: when a Sales person assigns a custom

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.