I am using preg_replace_callback, Here is what i am trying to do:
$result = '[code]some code here[/code]';
$result = preg_replace_callback('/\[code\](.*)\[\/code\]/is', function($matches){
return '<div>'.trim($matches[1]).'</div>';
}, $result);
The idea is to replace every match of [code] with <div> and [/code] with </div>, And trim the code between them.
The problem is with this string for example:
$result = '[code]some code[/code]some text[code]some code[/code]';
What i want the result to have 2 separated div's:
$result = '<div>some code</div>some text<div>some code</div>';
The result i get is:
$result = '<div>some code[code]some text[/code]some code</div>';
Now i know the reason, And i understand the regex but i couldn't come up with solution, If anyone know how to make it work i will be very thankful, Thank you all and have a nice day.
/\[code\](.*?)\[\/code\]/is.