Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>string urlencode ( string $str )</p> <p><a href="http://php.net/manual/en/function.urlencode.php">http://php.net/manual/en/function.urlencode.php</a></p> <p>Actually here is a great post about converting text like your example above to nice url-safe strings (probably better for you than the above function): </p> <p><a href="http://cubiq.org/the-perfect-php-clean-url-generator">http://cubiq.org/the-perfect-php-clean-url-generator</a></p> <pre><code>setlocale(LC_ALL, 'en_US.UTF8'); function toAscii($str, $replace=array(), $delimiter='-') { if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); } $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); return $clean; } </code></pre> <p>Here are examples of what it does:</p> <pre><code>echo toAscii("Mess'd up --text-- just (to) stress /test/ ?our! `little` \\clean\\ url fun.ction!?--&gt;"); returns: messd-up-text-just-to-stress-test-our-little-clean-url-function echo toAscii("Perché l'erba è verde?", "'"); // Italian returns: perche-l-erba-e-verde echo toAscii("Peux-tu m'aider s'il te plaît?", "'"); // French returns: peux-tu-m-aider-s-il-te-plait echo toAscii("Tänk efter nu – förr'n vi föser dig bort"); // Swedish returns: tank-efter-nu-forrn-vi-foser-dig-bort echo toAscii("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ"); returns: aaaaaaaeceeeeiiiidnooooouuuuyssaaaaaaaeceeeeiiiidnooooouuuuyy echo toAscii("Custom`delimiter*example", array('*', '`')); returns: custom-delimiter-example echo toAscii("My+Last_Crazy|delimiter/example", '', ' '); returns: my last crazy delimiter example </code></pre> <p>If you want to convert something like ä to ae and etc you can use a script like this (sorry, don't know about a better way of doing this):</p> <pre><code>setlocale(LC_ALL, 'de_DE'); $replace = array( 'illegal' =&gt; array('/Ä/', '/Ö/', '/Ü/', '/ä/', '/ö/', '/ü/', '/Â/', '/é/'), 'legal' =&gt; array('Ae', 'Oe', 'Ue', 'ae', 'oe', 'ue', 'Aa', 'e') ); $string = 'ich hätte gerne brötechen Mein Name ist Öles Âlex'; echo preg_replace($replace['illegal'], $replace['legal'], $string); //Output: "ich haette gerne broetechen Mein Name ist Oeles Aalex" </code></pre> <p>You can obviously <strong>put it all together</strong> like this (only converting ü->ue etc, just add more to the first preg_replace):</p> <pre><code>setlocale(LC_ALL, 'en_US.UTF8'); function toAscii($str, $replace=array(), $delimiter='-') { if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); } $clean = preg_replace(array('/Ä/', '/Ö/', '/Ü/', '/ä/', '/ö/', '/ü/'), array('Ae', 'Oe', 'Ue', 'ae', 'oe', 'ue'), $str); $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $clean); $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); return $clean; } $text = "Hätten Sie gerne viele Brötchen? Wenn ja dann einfach *!@#$%^&amp;*()eingeben..."; echo toAscii($text); //OUTPUT: haetten-sie-gerne-viele-broetchen-wenn-ja-dann-einfach-eingeben </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload