stuartmarsh Posted April 28, 2009 Share Posted April 28, 2009 I'm trying to replace text between {{PHP}} and {{/PHP}} but all that happens is my I get part of my text back. REGEX: /\{\{PHP\}\}(.*?)\{\{\/PHP\}\}/ SAMPLE:{{PHP}}TEXT{{/PHP}} RESULT: {{PHP}}TEXT EXPECTED RESULT: TEXT Can somebody tell me where I'm going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/ Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 Question mark is greedy. Why you use it at all here? Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/#findComment-821257 Share on other sites More sharing options...
stuartmarsh Posted April 28, 2009 Author Share Posted April 28, 2009 This regex is based on another that I found that did a similar thing. Can you tell me what I can do to make it do what I want? Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/#findComment-821272 Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 $str = "{{PHP}}TEXT{{/PHP}}"; preg_match("#\{\{PHP\}\}([^\{]*)\{\{/PHP\}\}#",$str,$match); var_dump($match); Ths will stop as soon as it encounters { though Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/#findComment-821283 Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 I think I got it preg_match_all("#\{\{PHP\}\}(.*?)(?=\{\{/PHP\}\})#",$str,$match); var_dump($match); Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/#findComment-821306 Share on other sites More sharing options...
stuartmarsh Posted April 28, 2009 Author Share Posted April 28, 2009 Many thanks Mchl that's great. Quote Link to comment https://forums.phpfreaks.com/topic/156002-solved-replace-text-between-php-php/#findComment-821439 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.