By davecoventry on
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
Why don't you use pathauto?
Why don't you use pathauto?
I am
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.
Could you tell me why you
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...)
why don't you use
why don't you use drupal_get_path_alias ?
Solution
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.
l & url
Both l() and url() will output the alias (eg articles/pretty-title) when fed with the menu path (eg node/1978) .