Jump to content

Simple question regarding preg_replace


Guest upirate

Recommended Posts

Guest upirate

I allow my users to enter text through a text area in a variable called input

 

 

$text = preg_replace("/[^a-zA-Z0-9\-\s\$\.\(\)\]\[]/i", "", $input);

 

 

How can I include the newline character to be allowed in my preg_replace statement.

 

 

 

Thanks!!!

 

 

 

Link to comment
Share on other sites

http://sg2.php.net/manual/en/reference.pcre.pattern.modifiers.php

 

s (PCRE_DOTALL)

    If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

Link to comment
Share on other sites

Guest upirate

thankyou for the post. I just have one last question to ask you and you seem like you can:

 

As I said before, I have this text area. I want the user to be able to cut and paste text from another site/document and for it to retain the paragraph and breaks. (but without any malicious tags etc)

 

 

do you know of any place where I can find the code ?

 

 

thanks again for the reply

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.