UnknownPlayer Posted July 4, 2011 Share Posted July 4, 2011 How can i make url with www.domain.com/article/name-of-article ? If someone can give me example ? Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted July 4, 2011 Share Posted July 4, 2011 http://monkeytooth.net/2010/12/htaccess-php-how-to-wordpress-slugs/ Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 4, 2011 Author Share Posted July 4, 2011 This is nice, but how can i avoid special chars in article name, i mean in url ? Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 4, 2011 Author Share Posted July 4, 2011 And if there is some other example, can you please give me link ? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 5, 2011 Share Posted July 5, 2011 Strip any special characters out of the string before using in the url:  Try it out: <?php function prepare($string) { $blacklistchars = '#[^-a-zA-Z0-9_ /]#'; $string = preg_replace($blacklistchars, '', $string); $string = trim($string); $string = preg_replace('#[-_ ]+#', '-', $string); $string = strtolower($string); return $string; } $title = "This string 'contains' && stuff to remove in the url £ *** $"; $title_for_url = prepare($title); echo $title_for_url; exit(); ?> Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 5, 2011 Author Share Posted July 5, 2011 Should i save this string in mysql and when url is with that string to read from mysql if exist that string like in url ? btw thanks Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 5, 2011 Share Posted July 5, 2011 you can do, or just run the title through the function and compare it against the url parameter Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted July 6, 2011 Author Share Posted July 6, 2011 Oh yes.. thanks.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.