0

hey guys im really frustrated

im looking for a way to retrieve back my slug to the normal text as wordpress does

in wordpress there is a function to do so :

apply_filters('editable_slug', $slug)

i search all related files to find what this function does, but couldn't understand a bit.

as ypu may know , making a slug out of a normal text is a easy job , but when its converted , for Utf-8 languages such as Arabic , words will be changed to unreadable unicodes .

e.g. :

http://localhost/page/%d8%a7%d9%84%d9%84%d9%87

do you know how this function works in wordpress ?

apply_filters('editable_slug', $slug)

and how i can do the same in my own php project ?

Mac Taylor
  • 5,020
  • 14
  • 50
  • 73

2 Answers2

1

Check out this question: Unicode characters in URLs for some good background.

The URL you show looks okay basically - it's the proper percent encoded representation of the arabic characters in question.

You should be able to display them in proper arabic on your web page. Copy+pasting will give you the URLencoded form, which is a good thing because that way, your permalinks will work in non-UTF-8-speaking clients as well.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • thanks but i need to show them in table columns , not in my address bar , hope you understand that , and that's why wordpress uses that function – Mac Taylor May 17 '10 at 15:39
  • @Mac Taylor the characters should turn up as proper arabic in your page. Can you show a live example? – Pekka May 17 '10 at 15:39
  • i did , and its there in my question post :( again : http://localhost/page/%d8%a7%d9%84%d9%84%d9%87 u cant see these unidefined characters after page/ ? it should be like this الله not %d8%a7%d9%84%d9%84%d9%87 , wordpress uses apply_filter to solve this problem – Mac Taylor May 17 '10 at 15:43
  • @Mac I see. They are not undefined characters, but the percent encoded representation of the arabic literals. Hmm... `urldecode()` would probably be the solution but I don't know how to get that into the Wordpress filtering thingy, sorry. – Pekka May 17 '10 at 15:45
1

Call rawurldecode on the percent-encoded form -- this will give you the text in UTF-8 encoding. If your webpage encoding is UTF-8, you just have to call htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8').

Example:

$str = rawurldecode('%d8%a7%d9%84%d9%84%d9%87');
echo htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');
Artefacto
  • 96,375
  • 17
  • 202
  • 225
  • thanks i took your advice and i got an error : htmlspecialchars($slug, ENT_NO_QUOTES, 'UTF-8') Warning: htmlspecialchars() expects parameter 2 to be long, string given in... – Mac Taylor May 17 '10 at 15:46
  • sorry, it put an extra underscore. However, after reading the discussion in Pekka's answer, I'm not sure I understood your question. – Artefacto May 17 '10 at 15:48
  • OK, I apparently I did :p Don't forget to call htmlspecialchars! – Artefacto May 17 '10 at 15:50