Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more: , +
I have to change a javascript function into php function, which convert unicode data. it's ok for changing simple replace function into php preg_replace e.g.
JavaScript
var output = str.replace(/\u104E\u1004\u103A\u1038/g, '\u104E');

into
PHP
$output = preg_replace('/\u104E\u1004\u103A\u1038/g', '\u104E',$str);

My problem is that how to convert following javascript replace function with inline function. e.g.
JavaScript
output = str.replace(/([\u103B\u103C][\u103D]?[\u103E]?[\u102D\u1036]?)\u1030/g, function($0, $1)
   {
      return $1 ? $1 + '\u1034' : $0 + $1;
   }
   );

I have no idea how inline function works and how to implement it in php. Please help me how to solve this problem.
Posted
Comments
Sunasara Imdadhusen 7-May-14 6:04am    
But why you want to convert same function in PHP because from the PHP you can use javascript.
cradion 8-May-14 3:13am    
sure, but I want to get output as string to implement as server side method instead of directly displaying result and output buffering cannot be used for this purpose as output buffer will produce javascript code.<br><br>
There are some other techniques such as pecl v8js php extension to invoke javascript function directly on server side, but I don't want to use this way for such string manipulation purpose.
Sunasara Imdadhusen 8-May-14 3:20am    
Thanks, so can you please explain what your requirement instead of understand above code so will try to give you alternate solution.
cradion 8-May-14 3:30am    
My problem is that I don't know how to implement second parameter inline function in php
function($0, $1)
{
return $1 ? $1 + '\u1034' : $0 + $1;
}
I want to know how to get regex-matches from pattern
Sunasara Imdadhusen 8-May-14 3:35am    
Ok, what are the value of str variable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900