php - preg_replace not working in for loop -


i want include files using shortcode, problem preg_replace isn't working in loop.my code below:

    <?php $output = "[@include('file1')] [@include('file2')]"; if(preg_match_all("/\[\@include\(\'(.*?)\'\)\]/", $output, $match)){     for($i=0;$i<count($match);$i++){         $output = preg_replace("/\[\@include\(\'(.*?)\'\)\]/", $match[1][$i], $output);     } } echo $output; 

the above code prints "file1 file1", should print "file1 file2" both file name not printing both files name.please tell i'm wrong.

what you're looking in output array of regular expression (i.e. in $match array), need using implode()!

<?php $output = "[@include('file1')] [@include('file2')]"; preg_match_all("/\[\@include\(\'(.*?)\'\)\]/", $output, $match); echo $out = implode(' ', $match[1]); ?> 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -