Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   ***Generate URL from text*** (https://www.warriorforum.com/programming/205243-generate-url-text.html)

Peter Hupuczi 24th April 2010 09:10 AM

***Generate URL from text***
 
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;
 
      }


stma 24th April 2010 10:08 AM

Re: ***Generate URL from text***
 
PHP: Introduction - Manual

Peter Hupuczi 25th April 2010 04:08 AM

Re: ***Generate URL from text***
 
Quote:

Originally Posted by stma (Post 2023815)

Thanks for reply! However this does not resolved m any of my problem :)

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. :)

Manfred Ekblad 25th April 2010 04:33 AM

Re: ***Generate URL from text***
 
Check the third comment from the top at PHP: preg_replace - Manual

Is it something like that you are looking for?

Peter Hupuczi 25th April 2010 04:58 AM

Re: ***Generate URL from text***
 
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 ;
 
      }

This code at the moment the code simply leave out from the generated url all the characters mentioned above (iso-8859-2)(Hungarian)

Manfred Ekblad 25th April 2010 05:08 AM

Re: ***Generate URL from text***
 
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('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
$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)));
}
?>

Peter Hupuczi 25th April 2010 05:39 AM

Re: ***Generate URL from text***
 
Quote:

Originally Posted by Manfred Ekblad (Post 2026282)
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()
{
= array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', '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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(, , );
}

function post_slug()
{
return strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'),
array('', '-', ''), remove_accent()));
}
?>

Yes I did but this does not work for me....

Only that code works what I mentioned above! And that need to be modify! :D

Manfred Ekblad 25th April 2010 06:11 AM

Re: ***Generate URL from text***
 
:D

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

Peter Hupuczi 25th April 2010 06:47 AM

Re: ***Generate URL from text***
 
Quote:

Originally Posted by Manfred Ekblad (Post 2026394)
:D

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

I think this is not as simple as it sounds...

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.

Manfred Ekblad 25th April 2010 07:16 AM

Re: ***Generate URL from text***
 
...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?

stma 25th April 2010 09:57 AM

Re: ***Generate URL from text***
 
Quote:

Originally Posted by Peter Hupuczi (Post 2026158)
Thanks for reply! However this does not resolved m any of my problem :)

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. :)

The iconv functions are used to clean up text.

stma 25th April 2010 11:25 AM

Re: ***Generate URL from text***
 
Here is the function page instead of the overview.

PHP: iconv - Manual

weaveronline 25th April 2010 11:35 AM

Re: ***Generate URL from text***
 
Yes, I too suggest iconv function

Peter Hupuczi 26th April 2010 03:26 AM

Re: ***Generate URL from text***
 
Quote:

Originally Posted by Manfred Ekblad (Post 2026589)
...so you have to keep all the modifications inline within your generateUrl()-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?

Yes I have to...

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.

Manfred Ekblad 26th April 2010 04:10 AM

Re: ***Generate URL from text***
 
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?

Number_5 29th April 2010 12:21 AM

Re: ***Generate URL from text***
 
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.

Manfred Ekblad 29th April 2010 02:52 AM

Re: ***Generate URL from text***
 
Exactly... I'm also intrigued by this.

How's the progress for you Peter?


All times are GMT -6. The time now is 10:44 AM.