ok, im pretty newbish to regular expression and i'd like some help.
I want to read a string for the following characters:
< > | [ ] - + \ /
Then replace those characters with a NULL or white space.
Anyhelp?
Regular Expressions - String search and replace
Moderator: General Moderators
try this one
Code: Select all
<?php
$testtext = '<>|[]-+\/';
$pattern = '![<>|\[\]\-+\\\/]!';
echo preg_replace($pattern, '', $testtext);
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
If you just want to get rid of those particular characters then it is not really necessary to use regular expressions, instead you could just use str_replace():
Mac
Code: Select all
$original = '<>|[]-+\/';
$from = array('<', '>', '|', '[', ']', '-', '+', '\'', '/');
$adjusted = str_replace($from, '', $original);Thx alot
Hey thx everyone, though it was an easy solution (which really made me feel like an idiot) i've bee strugling with the problem for a good 4 days. Usually im not that bad of a php guy..ahh well. Could anyone reccommend a good regular expresion tutorial? Just to find all the good stuff on it..thx in advance.
Here are a couple pretty good regex tutorial links that I had laying around...
http://japhy.perlmonk.org/book/
http://www.perldoc.com/perl5.6/pod/perlre.html
and as always, there is the PHP manual's documentation for regexes...
http://www.php.net/manual/en/pcre.pattern.syntax.php
http://japhy.perlmonk.org/book/
http://www.perldoc.com/perl5.6/pod/perlre.html
and as always, there is the PHP manual's documentation for regexes...
http://www.php.net/manual/en/pcre.pattern.syntax.php