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? 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? 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? 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 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); 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. 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
Archived
This topic is now archived and is closed to further replies.