I've placed this ugly hack in my block to convert the article title into the articles URL.

<?php
function gen_path($str){
	$str=strtolower(rtrim(strip_tags($str)));
	$split=preg_split("/\s/",$str);
	$oput='';
	foreach($split as $el){
		$el=alphanumeric_only($el);
		switch ($el){
			case 'a':
			case 'an':
			case 'the':
			case '':
			case 'in':
			case 'to':
				break;
			default:
				if($oput==''){$oput=$el;}
				else {$oput.='-'.$el;}
		}
	}
	return $oput;
}
?>

It works currently (I didn't have time to post here and wait for an answer), but there must be a way of doing this that is a lot more compliant.

Not to mention future proof.

Can anyone tell me what it is?

Comments

WildKitten’s picture

Why don't you use pathauto?

davecoventry’s picture

Yes.

I am using Pathauto.

That's why my URLs have the title-of-the-article as part of the path.

What I want to do is duplicate the method of converting the title to the path so that I can insert them into my redirects.

WildKitten’s picture

Could you tell me why you need those redirect? Do you need to redirect after some action(for example, when user add comment, or change content...)

Anonymous’s picture

why don't you use drupal_get_path_alias ?

davecoventry’s picture

Rather than do this I'll just use the nid from my SQL query and use the URL /node/$nid .

It's actually for a drop down menu to link to the article, for those of your asking.

heine’s picture

Both l() and url() will output the alias (eg articles/pretty-title) when fed with the menu path (eg node/1978) .