Re: explode and escape character for string separator
| From: | Cesar Cordovez | Date: | Fri, 18 Jul 2003 20:29:04 +0000 |
| Subject: | Re: explode and escape character for string separator | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155836@lists.php.net to get a copy of this message | ||
Among other things, this is why XML exists. Use XML. FLASH can handle it, PHP can handle it, everything out there can handle it. Use XML. Delimiters will sooner or later break down. Use XML.
Over and out.
Grant Rutherford wrote:
Chris Shiflett wrote:--- Reuben D. Budiardja wrote:I like the way you encode things like $ in php. $ = delimiter /$ = $ //$ = /delimiter ///$ = /$ ////$ = //delimiter /////$ = //$ etc. //// = // /$/$ = $$ etc. To encode the input, just change every / to a // and every $ to a /$. Decoding is the opposite. I don't think that there are any weird situations that can screw this up. You can use the same escape character "/" for any special character, ie /@ or /: if necessary. GrantI did strive for that. But whatever character I choose, the problem remains that we can't guarantee that it's going ot be only used as deliminater, since the deliminated string is an input from user. So the problem remains.Well, just to point out, your delimiter can be anything, including: )!@#$%^&*(donotusethisstringofcharactersinanything(*&^%$#@!) Of course, at some point, that method of playing with probability becomes unrealistic, and it is imperfect. John's suggestion of URL encoding is likely your best bet. Given your string: $foo:$bar:$blah Make that instead: urlencode($foo) . '&' . urlencode($bar) . '&' . urlencode($blah) Then you can use & as your delimiter and be guaranteed that it does not exist within each string. It is also easy to recover the original strings, and since you are using PHP functions, there is less code to write (always a big plus). Hope that helps. Chris ===== Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/