0
votes

I need to use preg_match_all to repeat occurrence within a given text. eg.

input: "Lorem Ipsum is simply [repeat] dummy [/ repeat] text of the printing and typesetting industry."

output: "Lorem Ipsum is simply dummy dummy text of the printing and typesetting industry."

examples have already tried but my limitations do not help.
I am grateful for who can help me, thanks

2
Please post the code you tried - Yan Berk

2 Answers

1
votes

Simply use preg_replace :

$output = preg_replace ("#\[repeat\](.+)\[/repeat\]#isU", "$1$1", $input);

and you're done. :)

0
votes

You will also need to replace occurrences of [repeat].

Based on @Jerska answer:

$output = preg_replace ("#(\[repeat\])(.+)(\[/repeat\])#isU", '$2$2', $input);