I have an editable filesystem where user can submit changes in a form.
I would like to use the path of the files as NAME or ID Tags.
Since i doubt i am the first facing this, there might be a better approach.
Examples:
path: ../../disney/mouse/mickey.php
Known restrictions:
Jquery: no periods (.) and colons (:)
HTML : Only letter, digits,hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
HTML5: All but no spaces ( ) and at least 1 char.
It is required that PHP AND JAVASCRIPT can easily encode/decode the string in both ways.
atm i do it by replacing “/” & “.” with unusual patterns.
Which encoding you advise and is there something that even SHRINKS the path but stays unique??
Regards :>
EDIT: USers can alter and edit the code from the files. Why do you advise me to use an additional input for each field which links the path with the content? i don’t see the point since its not a problem if the name or id tags are properly encoded.
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…
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.
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.
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.
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.