Reputation: 337
The below call to preg_replace
fails and returns an empty string when content
contains accented characters such as à
or ÿ
.
preg_replace('@([^=][^"])(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.\%\+#-]*(\?\S+)?[^\.\s])?)?)@', '$1<a href="$2" target="_blank">$2</a>', $content);
I rewrote the regex in preg_replace
this way, and it worked:
preg_replace('@([^=][^"])(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.\%\+#ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ-]*(\?\S+)?[^\.\s])?)?)@', '$1<a href="$2" target="_blank">$2</a>', $content);
How can I make it shorter?
Upvotes: 1
Views: 63