preg_replace help

Thread Solved

Join Date: Dec 2007
Posts: 624
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 9
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

preg_replace help

 
0
  #1
Jun 29th, 2009
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:
  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.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,426
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 230
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: preg_replace help

 
1
  #2
Jun 29th, 2009
If you want everything accept for letters and numbers you can use
  1. $pattern = '/[^a-z0-9]/i';
If you are specific about \/:"?<*>| then it's this
  1. $pattern = '#[\/:"\?<\*>|]#';
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 624
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 9
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: preg_replace help

 
0
  #3
Jun 30th, 2009
Thanks for the solution.

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

Thankyou.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,426
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 230
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: preg_replace help

 
0
  #4
Jun 30th, 2009
Originally Posted by OmniX View Post
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
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC