Hi Guys,
I dont know if this is only for questions, but this forum has been so helpful to me, and when one of the most helpful posters Laser Light suggest urlencode to me for generating urls from article titles, I thought I would share my better alternative, as I hate all those %20's in my urls.
I post my article into a html form,
and then on my action page, (form action="action_page"), after the article is inserted into the DB for seo purposes I assign all thr html for the article page to a variable, with the php post variables inside the correct tags, i.e.
<title>$title</title> etc.
then I write it to a file using fopen() fwrite, and here is how I use the article title divided by hyphens as the file name, and have included eregi's to remove apostrophes, colons and other potential characters not suitable for urls, from my titles.
$splitname = split(" ",$title);
$counttitle = count($splitname);
$f = 0; while ($f < $counttitle) { $worker = substr($splitname[$f],-1); if (!eregi("[a-z0-9]",$worker)) { $splitname[$f] = substr($splitname[$f],0,-1); } $worker2 = substr($splitname[$f],-2,1); if (!eregi("[a-z0-9]",$worker2)) { $splitname[$f] = substr($splitname[$f],0,-2); $splitname[$f] .= $worker; } $filename .= $splitname[$f]; $filename .= "-"; $f++;};
$smalltitle = strtolower($filename);
$fintitle = substr($smalltitle,0,-1);
$test = substr($fintitle,-1);
if ($test == "-") { $fintitle = substr($smalltitle,0,-2); }//Make sure the last charachter isn't a hyphen//
$finfolder = substr($smallfolder,0,-1);
$file = "/files/home3/warpages/";
$file .= $finfolder; // I used the same while loop to put dashes between the section name, also selected on the html form//
$file .= "/";
$file .= $fintitle;
$file .= ".php";
$create = fopen("$file","w");
fwrite($create,"$write");
fclose($create);
chmod("$file",0755);
Might be a lot of code but for me it beats urlencode, to have nice neat hypen seperated urls. And I use the same code to link to the articles when I pull them back out of the database. Like I say lotta lotta code but it floats my boat.