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

  • SEARCH
  • Home
  • 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 6365955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:21:37+00:00 2026-05-25T00:21:37+00:00

My idea is to remove special characters and html codes and replace the whitespaces

  • 0

My idea is to remove special characters and html codes and replace the whitespaces to dashes
let us doing it step by step

$text = "Hello world)<b> (*&^%$#@! it's me: and; love you.<p>";

now i’m want the output become Hello-world-its-me-and-love-you
I’ve tired this code for removal of special characters and html codes

$array = array();
$array[0] = "/<.+?>/";
$array[1] = "/[^a-zA-Z0-9 ]/";

$textout= preg_replace($array,"",$text);

Now the output will be like this Hello world its me and love you
so is there any way i can modify this code so that the text output become exact as i do needs Hello-world-its-me-and-love-you

~ thank you

  • 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-25T00:21:37+00:00Added an answer on May 25, 2026 at 12:21 am

    You’re probably better off using strip_tags to get rid of the html tags for you, then use a regexp to remove all non alphanumeric (or non-space) characters. Then you can simply convert spaces to hyphens using str_replace. Note I also added a line to collapse multiple spaces to a single space, since that is what you did in your example. Otherwise you get world--its-me instead of world-its-me.

    <?php    
        $text = "Hello world)<b> (*&^%$#@! it's me: and; love you.<p>";
        $text = strip_tags($text);
        $text = preg_replace('/[^a-zA-Z0-9 ]/', '', $text);
    
        //this is if you want to collapse multiple spaces to one
        $text = str_replace ('  ', ' ', $text); 
    
        $text = str_replace (' ', '-', $text);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any idea how to remove the Text Message button for this
I'm trying to remove excess whitespace from a string like this: hello        world
I have no idea how to remove invalid characters from a string in Java.
Any idea why the following code doesn't print the amount of characters in the
I am attempting to remove a class from an html tag using JavaScript but
With the help of friends I've got exact answer for removal of HTML codes
Anyone have any idea how to get the SACL's on a remote service using
idea Via jQuery, I was able to mark all :first-child and :last-child elements in
idea I would like to create a little app for myself to store ideas
any idea how if the following is possible in PHP as a single line

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.