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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:28:14+00:00 2026-06-10T02:28:14+00:00

I am having a text area in my UI and I would like to

  • 0

I am having a text area in my UI and I would like to filter out all xml(including html) text entered by user using preg_replace. I need a some help with it.

Eg:

Emailed user sam at 12:15 PM
<details><email>sam@sam.com</email></details>

After preg_replace :

Emailed user sam at 12:15 PM

Along with this any pointers to preg_replace regex would be great. I tried using some java regex(I am new to PHP) in preg_replace and found that it did not work. I am not sure if my regex was wrong or preg_replace uses different kind of regex.

All your help is much 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-06-10T02:28:16+00:00Added an answer on June 10, 2026 at 2:28 am

    mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

    So something like the following will work in most cases,

    $str_out = preg_replace('/<[\/]{0,1}\w[^>]*>/g', '', $str_in);
    

    Where '/<[\/]{0,1}\w[^>]*>/g' is regex for <name stuff> and </name stuff>. It will fail if you’ve a > in an attribute (i.e. <name blah=">hello"> will result in hello">

    Although strip_tags is native so will be faster. Remember the arguments for strip_tags are the things to not strip


    EDIT: If you want the content between the tags stripped out too, the regex for that is '/<\w[^>]*>[\s\S]*?<\/\w[^>]*>/g', but this will fail in even more situations (i.e. badly closed/nested tags), so you might want to run it first then the above on the result to make sure.

    EDIT: Spelling

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

Sidebar

Related Questions

I am having trouble copying text using zeroclipboard. This is my html code: <dl
I'm having problems wrapping text within my container. I've already searched and all answers
I have a text file and would like to import it into MATLAB and
I have a full screen fixed background image. I would like the text in
I really like Backbone, but I am having the hardest time doing what would
I have a PHP Script which has several text areas. What I would like
I'm using the Edit-in-Place JQuery plugin, JEditable: http://www.appelsiini.net/projects/jeditable . I would like to use
Good morgning, I would like to be able to analyze text where I am
I'm having 2 problems. 1 - I have a text area in which I
I am using Visual Studio 2010 Pro for simple C programming, I would like

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.