rfighter Posted August 3, 2008 Share Posted August 3, 2008 Hi, I am not really confident with the usage of preg_replace, and I would appreciate if someone could help me with the line of code. I have a string, e.g. "sfsdfd sdfd dfsdfsf sfdfdf" What I would like to do is replace the " (* denoting wildcard) with just "[QUOT]". Thanks! ^("QUOT" should be "QUOTE") Link to comment https://forums.phpfreaks.com/topic/117957-preg_replace-and-wildcards/ Share on other sites More sharing options...
unkwntech Posted August 3, 2008 Share Posted August 3, 2008 preg_replace('/ - .*/i' , '', $text); This should do the trick Link to comment https://forums.phpfreaks.com/topic/117957-preg_replace-and-wildcards/#findComment-606807 Share on other sites More sharing options...
rfighter Posted August 3, 2008 Author Share Posted August 3, 2008 preg_replace('/ - .*/i' , '', $text); This should do the trick Unfortunately that didn't work. It turned: [quote - xyz] dfdfsdfsfsfsdsfdsfdsdsdsdsdsd [END OF QUOTE] Into: [quote I would like: [quote] dfdfsdfsfsfsdsfdsfdsdsdsdsdsd [END OF QUOTE] Link to comment https://forums.phpfreaks.com/topic/117957-preg_replace-and-wildcards/#findComment-606848 Share on other sites More sharing options...
nrg_alpha Posted August 4, 2008 Share Posted August 4, 2008 You mean something along these lines? $test = '[quote - fddfd ft er] dj hsh eh eklthe he [END OF QUOTE]'; $test = preg_replace('#(\[quote)[^\]]*(])#', '[quote]', $test); echo $test; Cheers, NRG Link to comment https://forums.phpfreaks.com/topic/117957-preg_replace-and-wildcards/#findComment-607380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.