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") Quote Link to comment 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 Quote Link to comment 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] Quote Link to comment 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 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.