can you help me with a function to replace string as following:
The string the boo[k|ks] [is|are] on the table will output the book is on the table or the books are on the table according to an argument.
<?php
$unformated_str = "the boo[k|ks] [is|are] on the table";
$plural = true;
echo formatstr($unformated_str, $plural);
?>
Output:
the books are on the table
Forgive my poor english. I hope I made my question clear enough.
Here is a function that uses
preg_replace_callback():Try it out