Making keyword rich, human readable URLs

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I added a piece that will chop the title at the nearest whole word if the title exceeds $maxlength.. so you don't end up with half a word in a title.

IE:
title: "some long url with words chopped in half"
set to false: some-long-url-with-words-cho.html
set to true: some-long-url-with-words.html

[edit]
I used this code to do this:

Code: Select all

$text = explode('-',$text); 
$text = implode('-',array_diff($text,array(array_pop($text))));
If there is a function that will pop the last element of an array off and return the array minus that element, let me know. array_pop() returns only the last element, so i had to throw an array_diff() in there.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

don't know if this would be any better or not...

Code: Select all

$text = implode('-',array_slice($text, 0, count($text)-1));
Post Reply