Search code examples
phpformslaravel-4special-characters

Problems with generating links with special language specific charactors in Laravel


I'm browsing the web and stackoverflow now for quite a while and I don't seem to find the correct answer. I have the following issue in generating my URLs. I'm moving a project to Laravel and everything should work the same way as before. Basically the issue is, when I add a new event with my form and catch the inputs with either Input::get('name') or $_REQUEST['name'] I don't seem to be able to catch the charactors as I used to before. In the old project I caught the characters and converted them to html entities like ü and then for my URL in this case it was a ü to ue. I even imported the same functions I used but they don't work. Here is my input control function from the old project, also preventing SQL injections:

function checkinput($rawstring,$replacespace=0){
        $newstring=str_replace(array("'",chr(34),"â","å","Å","ä","Ä","æ","Æ","è","É","é","ë","ĕ","Ö","ö","ó","ø","Ø","Ü",
                        "ü","ň","ñ","ß","č"),
                    array("'",""","â","å","Å","ä","Ä","æ","Æ","è",
                        "É","é","ë","ĕ","Ö","ö","ó","ø","Ø","Ü",
                        "ü","ň","ñ","ß","č"   ),$rawstring);

    if($replacespace==1){
        $newstring=str_replace(" ", "_", $newstring);
    }
    return $newstring;
}

Could you help me make that work again? I saw that there is supposed to be a no-entities option to be set somewhere in the Laravel config, but I can't find where to do that. Thanks in advance!


Solution

  • To complete this post, I finally found the answer for my issue. Actually not that hard, if you know what you're looking for :-)

    I solved it with the htmlentities() php function, with some parameters, see below:

    $eventName = htmlentities(($_POST['name']), ENT_QUOTES, "UTF-8");

    with this I got my entities, not exactly the way I wanted them, but at least I got them. my ü for instance was converted to ü instead of the hex value ü. I adjusted the function, which converted the charactor back to ue for the URL and all works fine now.

    Thanks for your efforts!