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 Link to comment https://forums.phpfreaks.com/topic/24338-the-use-of-preg_replace/ Share on other sites More sharing options...
effigy Posted October 18, 2006 Share Posted October 18, 2006 What have you tried? Link to comment https://forums.phpfreaks.com/topic/24338-the-use-of-preg_replace/#findComment-110696 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. Link to comment https://forums.phpfreaks.com/topic/24338-the-use-of-preg_replace/#findComment-110706 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] Link to comment https://forums.phpfreaks.com/topic/24338-the-use-of-preg_replace/#findComment-110728 Share on other sites More sharing options...
dymon Posted October 18, 2006 Author Share Posted October 18, 2006 Thanks, it works fine. :) Link to comment https://forums.phpfreaks.com/topic/24338-the-use-of-preg_replace/#findComment-110731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.