slug

What is a “slug” in Django?

▼魔方 西西 提交于 2019-11-26 01:36:40
问题 When I read Django code I often see in models what is called a \"slug\". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? (I have read its definition in this glossary.) 回答1: A "slug" is a way of generating a valid URL, generally using data already obtained. For instance, a slug uses the title of an article to generate a URL. I advise to generate the slug by means of a function, given the title (or another

Remove all special characters from a string [duplicate]

风格不统一 提交于 2019-11-26 01:28:27
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Regular Expression Sanitize (PHP) I am facing an issue with URLs, I want to be able to convert titles that could contain anything and have them stripped of all special characters so they only have letters and numbers and of course I would like to replace spaces with hyphens. How would this be done? I\'ve heard a lot about regular expressions (regex) being used... 回答1: Easy peasy: function clean($string) {

How does Stack Overflow generate its SEO-friendly URLs?

我的未来我决定 提交于 2019-11-26 01:21:10
问题 What is a good complete regular expression or some other process that would take the title: How do you change a title to be part of the URL like Stack Overflow? and turn it into how-do-you-change-a-title-to-be-part-of-the-url-like-stack-overflow that is used in the SEO-friendly URLs on Stack Overflow? The development environment I am using is Ruby on Rails, but if there are some other platform-specific solutions (.NET, PHP, Django), I would love to see those too. I am sure I (or another

URL Friendly Username in PHP?

丶灬走出姿态 提交于 2019-11-26 00:58:18
问题 On my PHP site, currently users login with an email address and a password. I would like to add a username as well, this username they g\\set will be unique and they cannot change it. I am wondering how I can make this name have no spaces in it and work in a URL so I can use there username to link to there profiles and other stuff. If there is a space in there username then it should add an underscore jason_davis. I am not sure the best way to do this? 回答1: function Slug($string) { return

PHP function to make slug (URL string)

两盒软妹~` 提交于 2019-11-26 00:39:26
问题 I want to have a function to create slugs from Unicode strings, e.g. gen_slug(\'Andrés Cortez\') should return andres-cortez . How should I do that? 回答1: Instead of a lengthy replace, try this one: public static function slugify($text) { // replace non letter or digits by - $text = preg_replace('~[^\pL\d]+~u', '-', $text); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); // trim $text = trim($text

URL Friendly Username in PHP?

大兔子大兔子 提交于 2019-11-25 20:53:19
On my PHP site, currently users login with an email address and a password. I would like to add a username as well, this username they g\set will be unique and they cannot change it. I am wondering how I can make this name have no spaces in it and work in a URL so I can use there username to link to there profiles and other stuff. If there is a space in there username then it should add an underscore jason_davis. I am not sure the best way to do this? function Slug($string) { return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil