Replace deprecated preg_replace /e with preg_replace_callback [duplicate]

You can use an anonymous function to pass the matches to your function: $result = preg_replace_callback( “/\{([<>])([a-zA-Z0-9_]*)(\?{0,1})([a-zA-Z0-9_]*)\}(.*)\{\\1\/\\2\}/isU”, function($m) { return CallFunction($m[1], $m[2], $m[3], $m[4], $m[5]); }, $result ); Apart from being faster, this will also properly handle double quotes in your string. Your current code using /e would convert a double quote ” into \”.

Replace URLs in text with HTML links

Let’s look at the requirements. You have some user-supplied plain text, which you want to display with hyperlinked URLs. The “http://” protocol prefix should be optional. Both domains and IP addresses should be accepted. Any valid top-level domain should be accepted, e.g. .aero and .xn--jxalpdlp. Port numbers should be allowed. URLs must be allowed in … Read more

PHP replacing special characters like à->a, è->e

There’s a much easier way to do this, using iconv – from the user notes, this seems to be what you want to do: characters transliteration // PHP.net User notes <?php $string = “ʿABBĀSĀBĀD”; echo iconv(‘UTF-8’, ‘ISO-8859-1//TRANSLIT’, $string); // output: [nothing, and you get a notice] echo iconv(‘UTF-8’, ‘ISO-8859-1//IGNORE’, $string); // output: ABBSBD echo iconv(‘UTF-8’, … Read more

Convert plain text URLs into HTML hyperlinks in PHP

Here is another solution, This will catch all http/https/www and convert to clickable links. $url=”~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i”; $string = preg_replace($url, ‘<a href=”$0″ target=”_blank” title=”$0″>$0</a>’, $string); echo $string; Alternatively for just catching http/https then use the code below. $url=”/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/”; $string= preg_replace($url, ‘<a href=”$0″ target=”_blank” title=”$0″>$0</a>’, $string); echo $string; EDIT: The script below will catch all URL types and … Read more