0

i'm using Wordpress, and Woocommerce plugin for my store.

my website products link contains some Hebrew Links, the URL string looking good like this:

/he/product/מגבר-אוזניות-a-xduoo-xd05-plus-headphone-amplifier/

when i copy the URL link to share it looks like :

/he/product/%d7%9e%d7%92%d7%91%d7%a8-%d7%90%d7%95%d7%96%d7%a0%d7%99%d7%95%d7%aa-xduoo-xd05-plus-headphone-amplifier/

is there any possible solution?

user3783243
  • 5,368
  • 5
  • 22
  • 41
davidasor
  • 199
  • 1
  • 14
  • Read this: [What characters are valid in a URL?](https://stackoverflow.com/questions/7109143/what-characters-are-valid-in-a-url). Basically there's a relatively small set of (ASCII) characters wihch are allowed in a URL and everything else must be url-encoded, which is what you're seeing in your example. – ADyson Jul 19 '22 at 16:52
  • @ADyson so there is no way to "translate" the URL when i share it? – davidasor Jul 19 '22 at 17:03
  • Well I don't see why you can't share the original version - most browsers will url-encode it automatically if you paste it into their address bars. Not clear what you mean by "when I click the link to share"...what link is that, and what software drives it? You've tagged PHP and wordpress but then provided no real context about that, nor any code. – ADyson Jul 19 '22 at 17:19
  • There's a couple of things going on to be aware of. First, IRIs (as opposed to URIs) allow for extended characters, and there's a process for conforming user-agents to convert that to ASCII-escaped for servers. (I'm not clear if servers can accept IRIs.) Second, transporting Unicode is complicated, which is why browsers automatically convert to ASCII-escaped version for you when you copy, it is well-understood to be safe. Third, if you want to copy the URL from the address bar, copy everything except the `h` in the protocol and your browser shouldn't escape it anymore, just remember to add it. – Chris Haas Jul 19 '22 at 17:22
  • However, don't be surprised if an IRI bites you when transporting. Even saving it on disk could cause issues, especially on older computers. Also don't be surprised if you email it to someone and it breaks, or, if you are lucky, their machine will re-encode to ASCII-encoded automatically. Here's a sample bit of HTML that uses an IRI that I know my browser (Chrome 103) will ASCII-encode it when accessing it. `http://ko.wikipedia.org/wiki/위키백과:대문` – Chris Haas Jul 19 '22 at 17:23
  • What would be the **expected** output? What do you mean by "when i copy the URL link to share" - does this involve PHP after all? – Nico Haase Jul 19 '22 at 17:53

1 Answers1

-1

This code helps you to URL-encoded string to Hebrew string when copied to share...

$url ="/he/product/מגבר-אוזניות-a-xduoo-xd05-plus-headphone-amplifier/";

$encode_url = urlencode($url);

print_r($encode_url);

  • @user3783243 please use this to encode your Hebrew URL if you got any problem ask in comment section – Usama Rasool Jul 19 '22 at 17:53
  • Please add some explanation to your answer such that others can learn from it. This would also encode the slashes, which makes the whole URL unusable – Nico Haase Jul 19 '22 at 17:54
  • The urlencode() function is an inbuilt function in PHP that is used to encode the URL. This function returns a string that consists of all non-alphanumeric characters except -_. and replaces it with the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. – Usama Rasool Jul 19 '22 at 18:00
  • Please add **all** clarification to your answer by editing it. Also, please test the code you've shared - you will see that it won't return the string that is shown in the question – Nico Haase Jul 20 '22 at 10:41