Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Форумы / Cotonti / Extensions / Create Alias From Title

musiconly
#1 05.11.2009 06:00
Hey guys, I got stuck... again.. :(

Here's the thing, since I have 10,000+ pages and around 50 of them have alias, I want to auto create alias from page title.

I want to do this because of few reasons:
1. Improve current SEO
2. Prepare database for Cotonti(yep, still using Sed125) - my nice urls will look like site.com/category/alias

Anyways, I'm not even a mediocre PHP programmer so don't laugh at my approach. It's almost working :D

Basic idea (since my titles consist of croatian letters like č,ć,š,ž,đ):
Turn: Đorđe Balašević - koncert u Šibeniku
into: Dorde_Balasevic_koncert_u_Sibeniku


What's wrong? Well, I get this kind of output:

Đorđe Balašević opet u Kerempuhu - Đorde_Balasevic_opet_u_Kerempuhu_22
Šta ćeš bez mene? - Šta_ces_bez_mene_28

And it should be
Đorđe Balašević opet u Kerempuhu - Dorde_Balasevic_opet_u_Kerempuhu_22
Šta ćeš bez mene? - Sta_ces_bez_mene_28

As you can see, output IS case sensitive, and it shouldn't be since I'm using str_ireplace. Right?

I don't get it :O

And second thing, has anyone created this "plugin" already and is willing to share it :D I'm sure lots of people could use it.

Thanks in advance!
GHengeveld
#2 05.11.2009 07:24
You could make it all lowercase first. But then you won't have capitals in your url.

I'm sure there's an existing solution for this problem that I just don't know about.
musiconly
#3 05.11.2009 07:33
$rec = strtolower($rec)
outputs:
Đorđe Balašević opet u Kerempuhu - �orde_balasevic_opet_u_kerempuhu_22
changed format from ansi, to uft8 without bom, utf8.. and still weird char:S
Kilandor
#4 05.11.2009 09:31
Lombi has a solution from this that uses javascript. I'm sure he will post it when he see's this, It may already be posted somewhere I think?
musiconly
#5 05.11.2009 16:24
The only thing he posted was auto-create alias when adding new entry. I'm talking about creating the alias for the things that are already in database.
GHengeveld
#6 05.11.2009 20:29
Basically this is about replacing strange non-Latin-1 with their Latin-1 look-a-likes.
musiconly
#7 06.11.2009 02:19
... in case non-latin chars are present in string, and using that converted string as a page alias :)
seems to me i'll have to add capitalized letters in that replacement array :(
Lombi
#8 07.11.2009 21:40
lol i really dont get your problem. it replaces the small characters fine cause you put them in. it doesnt do anything to the big characters cause you HAVENT PUT THEM IN :)

just make another line, using BIG CHARACTERS :D
<a href="http://www.domenlo.com">Surreal Art</a>
musiconly
#9 07.11.2009 23:13
I'm using str_ireplace — Case-insensitive version of str_replace, so I guess I wouldn't need to put the capitalized ones in my array.

Since I haven't found solution for this specific problem, I included capitalized letters in array :)
Lombi
#10 10.11.2009 01:11
Yeah, on paper it sounds logical, however my own testing showed that php does not recognise those characters as lowercase versions of the other (and vice versa). So we've been doing dual-case replaces ever since.
<a href="http://www.domenlo.com">Surreal Art</a>