View Single Post
  #1 (permalink)  
Old 02-17-2007, 11:22 PM
riggd riggd is offline
New Pligger
 
Join Date: Dec 2006
Posts: 20
To satisfy the almighty google, I started fooling around with utils.php after a problem I had with the url input and creation.

I wanted underscores in my link titles instead of dashes, which is better seo for directories.

i.e.

yoursite.com/pligg-is-great/

is now

yoursite.com/pligg_is_great/

Is somehow more "readable" to the almighty's standards.

I'll post my libs/utils.php makeUrlFriendly function but don't expect it to work for you, it's kinda proof of concept, because my function is hacked up anyway

Code:
function makeUrlFriendly($input) {
	// this function taken from http://us2.php.net/manual/en/function.preg-replace.php#54517
	// then modified with the help of "j0zf" and "caomhin"
	Global $db;

	//steef: remove strange characters in friendly URLs (code by jalso)
	//w3c: escape the url using urlencode() when it has to be displayed.
	//$input = remove_error_creating_chars(utf8_substr($input, 0, 240));
	$input = utf8_substr($input, 0, 240);

// I wanted to keep these in ???	$output = preg_replace("/\b(an?d?|f?o(r|f)|the)\b/i" , "" , $input);

	// Replace spaces with underscores
	$output = preg_replace("/\s/e" , "_" , $input);  //here is the modified line
	$output = trim($output);

	// Remove non-word characters // this will break unicode chars
	//$output = preg_replace("/\W/e" , "" , $output);

	//$output = preg_replace( '/(_a_|_an_|_the_|_and_|_or_|_of_|_for_)/i', '_', $output );

	$output = str_replace("-", "", $output);
	$output = str_replace("--", "_", $output);
	$output = str_replace("\"", "", $output);
	$output = str_replace("'", "", $output);
	$output = str_replace(",", "", $output);
	$output = str_replace(".", "", $output);

	$n = $db->get_var("SELECT count(*) FROM " . table_links . " WHERE link_title_url like '$output%'");
	if ($n > 0)
	{return $output . "-$n";}
	else
	{return $output;}

}
You also have to change your .htaccess when it comes to a "story" rule. EVERY SINGLE OCCURANCE,

ithis is an example...

Code:
RewriteRule ^story/title/([a-zA-Z0-9-_]+)/?$ story.php?title=$1 [L]
notice the addidtion of the underscore, you could replace the trailing dash after the 9 but I still have stories with dashes, and I probably won't go back and change them.

Last edited by riggd; 02-18-2007 at 03:14 AM.
Reply With Quote