Welcome Guest, Not a member yet? Register   Sign In
Auto detecting urls inside text - urls have some arabic letters
#5

(03-09-2017, 11:50 AM)khashabawy Wrote: i do not have a url in a variable i have it inside a text !!

If you would rather not overide the helper, you can can replace the non-ASCII characters with urlencoded versions.

PHP Code:
function urlencode_first($match)
{
    return 
urlencode($match[0]);
}

function 
urlencode_utf8chars($text)
{
    return 
preg_replace_callback('/[^\x20-\x7f]/''urlencode_first'$text);
}

// then in your controller
$this->load->helper('url');
$url "https://soundeals.com/community/tag/";
$tag "ميكروفون";
$text "text before $url$tag and after";
echo 
urldecode(auto_link(urlencode_utf8chars($text))); 

which produces the following html

Code:
text before <a href="https://soundeals.com/community/tag/ميكروفون">https://soundeals.com/community/tag/ميكروفون</a> and after

You could even wrap last line in its own function for brevity if you prefer.
Reply


Messages In This Thread
RE: Auto detecting urls inside text - urls have some arabic letters - by zploskey - 03-09-2017, 12:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB