Project Description:
I need a PHP script/function where i can pass in a search string, a replacement string and a article with nested spinning syntax. The function will then make replacements in the article in a single location where the search string is found in every possible variation of a top level spinning block. If there are multiple replacement in a variation sentence, then replace the first occurrence only. If there are no replacements possible in the entire article, return a blank string.
E.g. 1
Replace "Search string" with "Replacement string"
{Search string {Search string i am to replace|Search string and again Search string|Search string to replace}|Search string}
Since "Search string" is in every possible outcome, we can make the replacement. The output string would be
{Replacement string {Replacement string i am to replace|Replacement string and again Search string|Replacement string to replace}|Replacement string}
E.g. 2
Replace "Search string" with "Replacement string"
{Search string {No string here|Search string and again Search string|Search string to replace}|Search string}
Since the "Search string" is not on every replacement path, no replacement can be made.
I wrote this function in vb.net and it took me around 3 hours, however my code is a bit slow. So instead of just porting it to PHP, i figured i would post the project here to see if someone else could do it better. I would like the script/function to be as fast as possible. And keep in mind that spinning blocks can be nested many levels.
My max budget is $40.