943,865 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 579
  • PHP RSS
Jun 29th, 2009
0

preg_replace help

Expand Post »
What I require is to replace \/:"?<*>| with a space.

I have done similar statements before but I have complete brain freeze at the moment. Hoping one of you can jog my memory. Always hated regex expressions never understood the logic behind them minus the A-Z and 0-9 and then all the brackets, etc. Blah!
Anyways:
php Syntax (Toggle Plain Text)
  1. $pattern = // This where I require the regex expression
  2. $replacement = " ";
  3. $string = "a\b/c:d*e?f"g<h>i|j";
  4. $test_string = preg_replace($pattern, $replacement, $string);
  5. echo $test_string;
  6.  
Last edited by OmniX; Jun 29th, 2009 at 3:30 pm.
Similar Threads
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Jun 29th, 2009
1

Re: preg_replace help

If you want everything accept for letters and numbers you can use
php Syntax (Toggle Plain Text)
  1. $pattern = '/[^a-z0-9]/i';
If you are specific about \/:"?<*>| then it's this
php Syntax (Toggle Plain Text)
  1. $pattern = '#[\/:"\?<\*>|]#';
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Jun 30th, 2009
0

Re: preg_replace help

Thanks for the solution.

If you have any good sites to refresh my memory of this stuff let me know.

Thankyou.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Jun 30th, 2009
0

Re: preg_replace help

Click to Expand / Collapse  Quote originally posted by OmniX ...
Thanks for the solution.

If you have any good sites to refresh my memory of this stuff let me know.

Thankyou.
http://http://www.regular-expressions.info/ is probably the most in depth. http://gskinner.com/RegExr is my favorite regex tool
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to buid a forum & blog app!!
Next Thread in PHP Forum Timeline: Background theme should be with mouse...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC