Re: Passing arguments to an internal function via array_map

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/11/2011, at 5:10 AM, Marc Guay wrote:

> Hi folks,
> 
> I'm trying to convert the contents of an array from utf8 to utf16
> (thanks for the headache MS Excel!).  I originally created a "user
> function" that just ran the text through
> mb_convert_encoding($text,'utf-16','utf-8') but now I'm wondering if I
> can't just use the internal function directly.  Apparently it's more
> complicated when the function requires arguments; I see example using
> mysql_real_escape_string() on php.net.
> 
> My current attempt looks like this:
> 
> $clean = array_map('mb_convert_encoding', $dirty_arr, array('utf-16','utf-8'));
> 
> but I believe this is actually passing an array to
> mb_convert_encoding() as the second argument rather than the 2nd and
> 3rd... Any ideas or am I chasing something that can't be done?
> 
> Marc


You need to pass a second and third array to array_map() with the same number of elements as the first array. The arguments to the callback function are the elements from each array at the same offset.

Something like $clean = array_map('mb_convert_encoding', $dirty_arr, array_fill(0, count($dirty_arr), 'utf-16'), array_fill(0, count($dirty_arr), 'utf-8'));
---
Simon Welsh
Admin of http://simon.geek.nz/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux