/    Sign up×
Community /Pin to ProfileBookmark

Replace non latin chars on permalink

Hello,
I’m working on a school project and i need to have a permalink field on the db for seo url.
I have a field on db that is name LajmeEmri that include the name of the article and another field LajmeLink that should be the permalink for seo. What i have now is this variable:

[code=php]$LajmeLink = preg_replace(“#[^a-z0-9-_]#i”, “”,str_replace(‘ ‘, ‘_’, $LajmeEmri));[/code]

But this does not replace non latin chars like ë or ç to latin ones (e and c). Can anoyone help me to make the permalink only with latin chars? I need to replace ë with e and ç with c.

Thank you!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 28.2010 — I think you'd have to come up with an array of characters to be replaced, then use it in str_replace().
Copy linkTweet thisAlerts:
@KleidiauthorNov 28.2010 — Thank you for your reply.

Is this a good idea?
[code=php]
$repkerko = array('&euml','&ccedil','&quot','&ldquo','&bdquo','&ndash');
$repndrysho = array('e','c',' ','','','');
$LajmeLink = preg_replace("#[^a-z0-9-_]#i", "",str_replace($repkerko, $repndrysho, $LajmeEmri));
[/code]

&euml = ë

&ccedil = ç

Thank you!
Copy linkTweet thisAlerts:
@NogDogNov 28.2010 — You could use a single array, where the keys are the search and the values are the replacement, then make use of array_keys():
[code=php]
$replace = array(
'ë' => 'e',
'ç' => 'c'
);
$text = str_replace(array_keys($replace), $replace, $text);
[/code]

This helps make sure you keep your search list and replacement lists of equal length and in sync.
Copy linkTweet thisAlerts:
@KleidiauthorNov 29.2010 — Thank you for the reply. It works and is what i need.

Thanks again!
×

Success!

Help @Kleidi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...