Category Archives: PHP

Make php project translation ready with gettext

I was working on php script that requires translation in multi-language, So I found two ways to make it translation ready with PO and MO files. Here are the two methods to translate a php project using gettext PO/MO files.

  1. PHP core Gettext library
  2. PHP Gettext class (Mainly written for wordpress)

PHP core Gettext requires GNU gettext package to be installed on system. Whereas PHP gettext class doesn’t have any dependency. It can directly ready MO file and extract translation text from that. Also It works on windows server without problem. So in this article I will guide you how to use php-gettext class. Continue reading

Linkify all urls in text with php

It is a good idea to convert all urls into links in your web application like contact form, comment forms, chat application etc. To find and replace all urls with their links we will use php preg_replace function. See below example

$text = "Hello Friends my website url is";
$text = preg_replace("~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~",'<a href="$0">$0</a>',$text);
echo $text;

Hello Friends my website url is