neuroxik Posted July 19, 2006 Share Posted July 19, 2006 Hey everyone, I've been struggling on my own for a while with this issue and thought maybe someone here could help. Basically, I'm running into problems because I use an AJAX script to keep the page from reloading on each request, but my requests ( using GET ) must inlcude a variable and a value, for example:[code=php:0]$artist = "<a href=\"?a=$encartist\">$aname</a>";[/code]$encartist only represents the urlencode'd artist name. The problem is some artists have special characters like ê,à, etc.. and I can't use a preg_replace that replaces these by let's say ê for ê because the ampersand in it awaits ( as I've understood it ) for a new variable, like in ?a=something&t=something. Whatever the reason is, it won't work. So I was wondering if you guys had something to let's say replace those special character (ê,à,è, etc) into hexdec's like %26 (amp) or whatever.Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/ Share on other sites More sharing options...
effigy Posted July 19, 2006 Share Posted July 19, 2006 I'm confused. Can't you urlencode both $encartist and $aname? [url=http://xkr.us/articles/javascript/encode-compare/]Javascript also has this ability[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-60551 Share on other sites More sharing options...
neuroxik Posted July 19, 2006 Author Share Posted July 19, 2006 [quote author=effigy link=topic=101118.msg399908#msg399908 date=1153328943]I'm confused. Can't you urlencode both $encartist and $aname? [url=http://xkr.us/articles/javascript/encode-compare/]Javascript also has this ability[/url].[/quote]Yeh, there's no problem with the url encoding, which gives as a result a url which looks like [b]britney+spears[/b] instead of [b]britney spears[/b] and other char replacements, but when I'm using AJAX, it won't work, so I had to addslashes and str_replace [b]&[/b] -> [b]%26[/b], but I don't want to str_replace every imaginable character, I know it may sound wierd, but with AJAX to send the requests, urlencode alone just won't work when you click on artists with special characters. I was wondering how I'd go about writing the preg_replace for all characters ( '/[^\x09\x0A\x0D\x20-\x7F]/e' ) to their hexadecimal value ( ex.: %26 ), cuz the only ones I found was the ord($0) to replace like the following which replaces something like { (which I don't want cuz it doesn't work with my ajax script). Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-60596 Share on other sites More sharing options...
effigy Posted July 19, 2006 Share Posted July 19, 2006 I still don't follow entirely; perhaps due to my lack of experience with AJAX. Below is an example... Do you need a sprintf in Javascript?[code]<?php $string = 'Große & schöne.';?><script type="text/javascript" language="javascript"> function _escape(obj) { alert(escape(obj.innerHTML)); }</script>Use Javascript's escape (click it =>) <span onclick="javascript:_escape(this)"><?php echo $string; ?></span><br /> or use PHP's urlencode:<?php echo urlencode($string);?><br /> or use PHP's printf:<?php $pieces = str_split($string); foreach ($pieces as $piece) { printf('%%%X', ord($piece)); }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-60618 Share on other sites More sharing options...
neuroxik Posted July 20, 2006 Author Share Posted July 20, 2006 None of them work, but thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-60909 Share on other sites More sharing options...
effigy Posted July 20, 2006 Share Posted July 20, 2006 [quote author=neuroxik link=topic=101118.msg400320#msg400320 date=1153389711]None of them work, but thanks![/quote]You're not helping me help you.... [i]What[/i] doesn't work? In my browser I see this:[quote]Use Javascript's escape (click it =>) Große & schöne.or use PHP's urlencode: Gro%DFe+%26+sch%F6ne.or use PHP's printf: %47%72%6F%DF%65%20%26%20%73%63%68%F6%6E%65%2E[/quote]Clicking the Javascript part results in:[quote]Gro%DFe%20%26amp%3B%20sch%F6ne.[/quote]Can you be clear on what you need? If this is AJAX, does that mean PHP cannot help at all? Is this purely javascript? What is the example code not doing that you need it to? Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-61011 Share on other sites More sharing options...
neuroxik Posted July 21, 2006 Author Share Posted July 21, 2006 I'm very sorry on not having been clear enough. Fortunately, some javascript god has fixed my problem, the problem was not in the php, but in my ajax file that handled the requests. I'm greatly grateful for the time you spent trying to help me which wasn't obvious considering I had little information to give. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/15049-preg_replace-for-hex/#findComment-61515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.