dymon Posted October 18, 2006 Share Posted October 18, 2006 Hi,I have to replace some symbols with empty string, for example:'\abd' to replace with '', I need to replace the back slash and 2 or 3 symbols after it with '', and no matter what the 2 or 3 symbols are.I know that for this I need the function preg_replace but I can not make it work.Thanks in advance.Dymon Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2006 Share Posted October 18, 2006 What have you tried? Quote Link to comment Share on other sites More sharing options...
dymon Posted October 18, 2006 Author Share Posted October 18, 2006 What I have tried is not really what I need :). As I write I don't understand how to use it correctly. $formated = preg_replace(array('/\w+/'),'', $formated);But this replace everything. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2006 Share Posted October 18, 2006 Try this:[code]<pre><?php $tests = array( '\abd', 'abd', 'xx\abdxx', 'xx\abxx', 'xx\axx', 'x\ax', 'x\a', ); foreach ($tests as $test) { echo "$test => "; echo preg_replace('/\\\(?:\w){2,3}/', '', $test), '<br/>'; }?> </pre>[/code] Quote Link to comment Share on other sites More sharing options...
dymon Posted October 18, 2006 Author Share Posted October 18, 2006 Thanks, it works fine. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.