maxudaskin Posted May 2, 2010 Share Posted May 2, 2010 Hey guys, I have some code in which I am trying to find [ code ]*[ / code ], explode the entire string into the segments, and return a flag for the matched part. Turn this: Some random content. [ code ]run main;[ / code ] That was the main program.[ code ]include 'random.php';[ / code ] into this: [0]Some random content. [1]run main; [2] That was the main program. [3]include 'random.php' With flags: [0]1 [1]3 Link to comment https://forums.phpfreaks.com/topic/200469-match-regex-in-string-and-return-all-as-array/ Share on other sites More sharing options...
Hybride Posted May 2, 2010 Share Posted May 2, 2010 So what's the code, and what's wrong with it that you're not getting the desired results? Link to comment https://forums.phpfreaks.com/topic/200469-match-regex-in-string-and-return-all-as-array/#findComment-1051992 Share on other sites More sharing options...
maxudaskin Posted May 2, 2010 Author Share Posted May 2, 2010 So what's the code, and what's wrong with it that you're not getting the desired results? What I have uses preg_match_all. It runs the code first then outputs the rest. I can't seem to figure out how to do it the other way. function parseInlineCode($string = NULL, $body = false) { $regex = "/\[code\](.+)\[\/code\]/i"; preg_match_all($regex, $string, $code); print_r($code); /*eval('?>' . $code[1][0] . '<?php');*/ $code = explode(";", $code[2]); for($i = 0; $i < count($code); $i++) { $this->runCode($code[$i], $body); } } Link to comment https://forums.phpfreaks.com/topic/200469-match-regex-in-string-and-return-all-as-array/#findComment-1051993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.