If you plan to use iconv()
to transliterate string in you PHP project, please, take this:
FROM alpine:3.4
RUN apk add --update php5-cli wget build-base php5-dev autoconf re2c libtool \
# Install GNU libiconv
&& mkdir -p /opt \
&& cd /opt \
&& wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz \
&& tar xzf libiconv-1.14.tar.gz \
&& cd libiconv-1.14 \
&& sed -i 's/_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");/#if HAVE_RAW_DECL_GETS\n_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");\n#endif/g' srclib/stdio.in.h \
&& ./configure --prefix=/usr/local \
&& make \
&& make install \
# Install PHP iconv from source
&& cd /opt \
&& wget http://php.net/distributions/php-5.6.24.tar.gz \
&& tar xzf php-5.6.24.tar.gz \
&& cd php-5.6.24/ext/iconv \
&& phpize \
&& ./configure --with-iconv=/usr/local \
&& make \
&& make install \
&& mkdir -p /etc/php5/conf.d \
&& echo "extension=iconv.so" >> /etc/php5/conf.d/iconv.ini \
# Cleanup
&& apk del wget build-base php5-dev autoconf re2c libtool \
&& rm /opt \
&& rm -rf /var/cache/apk/* \
&& rm -rf /usr/share/*
Sample PHP example file:
<?php
setlocale(LC_ALL,'en_US.UTF-8');
// your horrible slugify function
function slugify($text) {
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = strtolower($text);
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
print slugify('héhéhé') . PHP_EOL;
Shorter hack: