I have a string which is decoded as base36, ie 0-9a-z,
any other characters were decoded as follows: a unicode character code, converted to base36 and preceeded by capital letter ‘A’, and followed by letter ‘B’.
If multiple unicode chars appear, only the last one if followed by ‘B’.
Example:
zergme@wtfd-婴儿服饰.com
converted as:
zergmeA1sBwtfdA19Ahv8Ag1rAkctAub4A1aBcom
It was convenient to convert the data that way, but now I’m bashing my head on how to write a decode it back algorithm.
I already provided for a function that convert charcodes to the Unicode chars, which let be called ‘unichr($code)’;
…but I can’t think of a good way finding these chars.
I was trying to use regexp first, something like:
preg_replace('/A.*?B?(?=[AB])/',"$1",$mail);
But it didn’t work the way I wanted… And I also didn’t realize how to cast my custom convertion function aka ‘unichr()’ on the matches.
Then I was also thinking about manually finding chars with strpos(), but it also turned out to be messy.
Could you advice some pattern? Or whether I should elaborate on regexp or try to use some loop? I’m kinda blank… Thanks 🙂
LOLMAO
That is it, Looks like I figured out, thanks to your contribution:
'/A(.*?)((?=A)|B)/'
Have you looked into using
preg_replace_callback()instead? It takes a function instead of a string as the replace value, and will pass the matches to the function and use the function’s return value as the replace string.Loose example, you’ll have to play around a bit