Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should not be using your values as identifiers. This is not good practice and this is why you are encountering this problem. But if you want to do it anyway...</p> <p>If you want to use a single string for all languages, you need to create a single string that excludes all the restricted characters found in each language. If restricted characters are part of the path, things become more difficult to keep unique. I would recommend you take the full path, then use a preg_replace() to change all characters that are not expected to underscores. </p> <pre><code>$old = '../../disney/mouse/mickey.php'; $new = preg_replace('/[^a-z0-9]/i', '_', $old); echo $new; //Outputs: "______disney_mouse_mickey_php" </code></pre> <p>You will definitely want to modify this to add in more characters that are allowed. The less that you restrict, the less likely you are to have a collision of non-unique id/name attributes.</p> <p>If you want a method that is less prone to having a possible non-unique id/name, then you can wrap your path in md5() (PHP) to create a md5 hash. This is less friendly to read, but should be unique enough for most non-critical purposes.</p> <pre><code>$old = '../../disney/mouse/mickey.php'; $new = md5($old); echo $new; //Outputs: "403d07916233847221263553573c5321" </code></pre> <p>In response to your comments, here is my final attempt. This /custom/ function will encode a path that is both unique and readable in the source. This will also allow you decode into your original path string. The allowed characters and escape character are customizable so that you can find one that is usable in all languages you require. </p> <pre><code>function customPathEncode($old) { $chars_allowed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $escape_char = '%'; $new = ''; $old_length = strlen($old); for($i = 0; $i &lt; $old_length; ++$i) { if(false === strpos($chars_allowed, $old[$i])) { $new .= $escape_char.bin2hex($old[$i]); } else { $new .= $old[$i]; } } return $new; } echo customPathEncode('../../disney/mouse/mickey.php'); //Output: "%2e%2e%2f%2e%2e%2fdisney%2fmouse%2fmickey%2ephp" </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