tags:

views:

261

answers:

2

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 ?

+1  A: 

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.

Pekka
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
@Mac Taylor the characters should turn up as proper arabic in your page. Can you show a live example?
Pekka
i did , and its there in my question post :( again : http://localhost/page/%d8%a7%d9%84%d9%84%d9%87u 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
@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
u rocked buddy that was nice , awesome , urldecode works .................. :D
Mac Taylor
+1  A: 

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
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
sorry, it put an extra underscore. However, after reading the discussion in Pekka's answer, I'm not sure I understood your question.
Artefacto
no , u did , your answer was totally correct , thanks again
Mac Taylor
OK, I apparently I did :p Don't forget to call htmlspecialchars!
Artefacto