slug

Improve converting string to readable urls

我怕爱的太早我们不能终老 提交于 2019-12-23 16:45:57
问题 The following function rewrites urls from news and product titles that contain all sorts of characters. The string I wish to create consists of only alphanumeric values and "-", but no ending "-" or whitespace and no repeated "-". The below function works fine, but I wondered if there is any way to write it simpler or more efficient? function urlName($string) { $string = trim($string); // no open ends $string = strtolower($string); // all lowercase $string = strtr($string, 'äöåÄÖÅ', 'aoaaoa')

Problem in displaying a URL slug with dash

前提是你 提交于 2019-12-21 17:53:47
问题 I made a slug with dash for my stories URLs such as: Fetching records with slug instead of ID This is my code to create slug : function Slugit($title) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); $title = remove_accents(

Convert any title to url slug and back from url slug to title

跟風遠走 提交于 2019-12-21 09:17:58
问题 I want to convert any title e.g. of a blog entry to a user friendly url. I used rawurlencode() to do that but it gives me a lot of strange strings like %s . The algorithm should consider german chars like Ö, Ä, etc. I want to make a url from title and be able to get the title by decoding the url. I tried some of this code: http://pastebin.com/L1SwESBn that is provided in some other questions but it seems to be one way. E.g. HÖRZU.de -> hoerzu-de -> HÖRZU.de Any ideas? 回答1: You want to create

Validating a slug in Django

☆樱花仙子☆ 提交于 2019-12-21 04:35:07
问题 I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to £$(*£$(£@$&£($ in the title field, which is converted into a slug using Django slugify . Because none of these characters can be converted, Django returns an error. My question is, what should I put in the form validation method to raise a forms.ValidationError when the user uses a title like this? Thanks. 回答1: This question is half a

Is there an easy way to populate SlugField from CharField?

孤人 提交于 2019-12-20 08:56:34
问题 class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to get the slug field to autopopulate based on the title? Perhaps in the Admin and outside of the Admin. 回答1: for Admin in Django 1.0 and up, you'd need to use prepopulated_fields = {'slug': ('title',), } in your admin.py Your key in the prepopulated_fields dictionary is the field you want filled, and the value is a tuple of fields you want concatenated. Outside of admin, you can

Generating doctrine slugs manually

家住魔仙堡 提交于 2019-12-20 01:55:16
问题 I'm using sluggable behavior in my Symfony2 project, but now I would like to make many slugs for one page, based on different texts (current title, old title(s), users text from form input), and keep it in another table. And my question is - how to manually use doctrine extensions for any text? I can't find it anywhere. Perfect would be something like: /* careful - it's not a real, working code! */ $sluggable = new DoctrineSluggable(); $slug = $sluggable->generate('My own text!'); echo $slug;

What is the best way to clean a string for placement in a URL, like the question name on SO?

寵の児 提交于 2019-12-18 13:39:14
问题 I'm looking to create a URL string like the one SO uses for the links to the questions. I am not looking at rewriting the url (mod_rewrite). I am looking at generating the link on the page. Example: The question name is: Is it better to use ob_get_contents() or $text .= ‘test’; The URL ends up being: http://stackoverflow.com/questions/292068/is-it-better-to-use-obgetcontents-or-text-test The part I'm interested in is: is-it-better-to-use-obgetcontents-or-text-test So basically I'm looking to

What is the best way to store a unique URL Slug?

橙三吉。 提交于 2019-12-18 13:26:45
问题 I'm trying to generate some url 'slugs' for my website. It's based upon a single piece of user generated text. Now, i have made my own slug method, so i'm not after some code for that. What i'm wondering is where is the best place to determine if this slug is unique and then insert it because the slug field is a Unique Key Index. Originally, i had a trigger on any insert (against the table) so when the data is entered, the slug is then determined. I had a function that checked for the number

How to remove params from url codeigniter

廉价感情. 提交于 2019-12-18 09:02:50
问题 I have url like this : http://domain/sentencijos/autoriai/429/marselis-prustas , where sentencijos is a controller, autoriai is a method, 429(param) is marselis prustas ID. I want to remove this param (ID) but don't know how. Full url should look like this: http://domain/sentencijos/autoriai/marselis-prustas Can someone help me? Thanks 回答1: Replace slug with id in your URLs. This is how it works: 1) I'm assuming here a product website flow. 2) For a particular product page, displaying the

How to convert super- or subscript to normal text in C#

六眼飞鱼酱① 提交于 2019-12-18 05:55:32
问题 I'm writing a slug generator for making nice urls. I'd like to convert m² to m2, but in a generic way that does this for all superscript (or subscript), not just a simple replace statement. Any ideas? 回答1: Thanks Johannes, you set me on the right track. The code with which I got it to work looks as follows: public string ConvertSuperscript(string value) { string stringFormKd = value.Normalize(NormalizationForm.FormKD); StringBuilder stringBuilder = new StringBuilder(); foreach (char character