tags:

views:

25

answers:

3

Hello

Could somebody tell me the name of function that convert spaces to underscores and letters to lowercase for seo friendly uri's?

I know it's very easy function to implement but I want use function for this job if exists in Drupal already.

Regards

+1  A: 

I'm not sure what you are trying to accomplish, but you can do a lot with the pathauto module and clean urls.

Unless you are actually creating a custom module that will create your own url, the above mentioned configuration is pretty simple. If you are making a custom module, I have a pretty strong suspicion that making a nice URL would be core functionality.

Icode4food
Thanks, you are right,but I am trying add menu items programatically so thats why I need this functionality.
Szyman
+1  A: 

As LanguaFlash said, if you just need to auto-generate SEO-friendly URLs for your content, use Pathauto: that's what it was made for. Even if you have your own custom module with custom paths, you can hook into Pathauto's API to do all the URL generation for you.

That said, if you really need to throw caution to the wind generate your own clean URLs by yourself, think about creating a dependency on Pathauto and utilizing its two URL cleaning functions—pathauto_cleanstring() and pathauto_clean_alias()—which are used by Pathauto to do what you're trying to do.

Mark Trapp
Thank for the answer. pathauto_cleanstring() probalby do the job.
Szyman
A: 

Anyway I have another question.

I add menu item during saving content type. I want to have URI to this content type like this:

offers/parent-offer-name/sub-offer-name

I have 6 parent offers (just containers for sub-offers) and many sub offers references to parent by node reference.

After adding menu item I check this in site building->menus and choose last added menu item

I see this error similar to this: The path 'offers/parrent-offer/sub-offer1' is either invalid or you do not have access to it.

How can I config pathauto to allowed those kind of uri's??

Code that I use to add menu link during saving content:

$r = db_query("SELECT mlid FROM {menu_links} WHERE link_title='%s'", $referenced_node->title);
$res = db_fetch_array($r);
$item = array(
  'menu_name' => 'menu-offers',
  'link_path' => $referenced_node->path . '/' .pathauto_cleanstring($node->title),
  'link_title' => $node->title,
  'plid' => $res['mlid'],
  'hidden' => 0
);
Szyman