| | #1 |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
Hi, I have a code here which actually generate url from my articles title from a directory script. The questin is how can I make it to replace words like áóíúé etc... (iso-8859-2) characters into a friendly url. So from "á" will be "a" etc.. At the moment all these foriner characters getting replaced with " - " Can anyone help me to figure out this issue? Thx. ![]() Here is the code: Code:
function generateUrl($title) {
$title= preg_replace('/[^A-Za-z0-9-]/', ' ', $title);
$title= preg_replace('/ +/', ' ', $title);
$title= trim($title);
$title= str_replace(' ', '-', $title);
$title= preg_replace('/-+/', '-', $title);
$title= strtolower($title);
return $title;
} |
| | |
| |
| | #3 | |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
![]() I'm still struggling with this issue. There is any programmer out there who have a minute to have a look at this please?? Thanks. | |
| | ||
| |
| | #4 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
|
Check the third comment from the top at PHP: preg_replace - Manual Is it something like that you are looking for? |
| |
| | #5 |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
Hi, What I'm looking for is how I need to modify the code below to replace iso-8859-2 characters eg.: á, í, ó, é, ú, Á, Ó, É, etc... with a, i, o, e, A, O, etc.. Here is the code: Code: function generateUrl() {
= preg_replace('/[^A-Za-z0-9-]/', ' ', );
= preg_replace('/ +/', ' ', );
= trim();
= str_replace(' ', '-', );
= preg_replace('/-+/', '-', );
= strtolower();
return ;
} |
| | |
| |
| | #6 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
|
Hmm... did u read the comments on the link i posted? :p Here is some code i copy&paste from that page (thx to hello at weblap dot ro for the code): <?php function remove_accent($str) { $a = array('À', 'Á', 'Â', 'Ã',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'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); return str_replace($a, $b, $str); } function post_slug($str) { return strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($str))); } ?> |
| |
| | #7 | |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
Only that code works what I mentioned above! And that need to be modify! | |
| | ||
| |
| | #8 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
| ![]() im confused... lol could you tell me why it wouldnt work for you? do you have a limit to the amount of lines of code you are allowed to use? :p |
| |
| | #9 | |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
This is an article directory script and this function actually convert the title into url. It is fine in English language... But Since the site will operate in Hungary... That is whay I need this to be fixed. The directory script is from ArticleMS. | |
| | ||
| |
| | #10 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
|
...so you have to keep all the modifications inline within your generateUrl($title)-function? could you please give some more details... ...and a simple question, do you need some help or do you need someone to actually write the complete function for you? |
| |
| | #13 |
| HyperActive Warrior Join Date: 2010
Posts: 267
Thanks: 5
Thanked 6 Times in 6 Posts
|
Yes, I too suggest iconv function
|
|
Thanks & Regards, Reach us at dukeduke600@gmail.com. Web Design| Logo Design | Banner Design | Web Development | Mobile Applications [iPhone/iPad/Android/Windows Phone] | |
| |
| | #14 | |
| Junior War Room Member Join Date: 2009 Location: UK and Hungary
Posts: 158
Thanks: 65
Thanked 12 Times in 8 Posts
|
The function is already written but for an unknown reason is not working. We could not figure out what can be the problem. I'm attached a file. The file called core.php contains the original function which generate url from the title. If you open it with Notepad++ have a look at line 3605. The function starting there. But is actually not works it does not convert anything. What I have done: I have changed the original function to this function generateUrl($title) { $title= preg_replace('/[^A-Za-z0-9-]/', ' ', $title); $title= preg_replace('/ +/', ' ', $title); $title= trim($title); $title= str_replace(' ', '-', $title); $title= preg_replace('/-+/', '-', $title); $title= strtolower($title); return $title; } But now, it just ignore all the iso-8859-2 characters. | |
| | ||
| |
| | #15 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
|
Well, you could call one of the other functions from within that function and just have it return the string without the "strange" characters and then do the normal parsing. Or am I missing some crucial piece of information here? |
| |
| | #16 |
| Warrior Member Join Date: 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
Am I dense or is the attachment missing? Is your function within a class and can you post an example of you trying to use the conversion function that was already posted? From a brief look, it should do exactly what you are trying to accomplish, but you may not be implementing it correctly. |
| | |
| |
| | #17 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Bandung, Indonesia
Posts: 281
Thanks: 103
Thanked 193 Times in 55 Posts
|
Exactly... I'm also intrigued by this. How's the progress for you Peter? |
| |
|
| Bookmarks |
| Tags |
| generate, text, url |
| |