php/regex: “linkify” blog titles

 

Questions


I’m trying to write a simple PHP function that can take a string like

Topic: Some stuff, Maybe some more, it's my stuff?

and return

topic-some-stuff-maybe-some-more-its-my-stuff

As such:

  • lowercase
  • remove all non-alphanumeric non-space characters
  • replace all spaces (or groups of spaces) with hyphens

Can I do this with a single regex?

 

 

————————————————-

Answer

Many frameworks provide functions for this

CodeIgniter:
http://bitbucket.org/ellislab/codeigniter/src/c39315f13a76/system/helpers/url_helper.php#cl-472

wordpress (has many more in the code):
http://core.trac.wordpress.org/browser/trunk/wp-includes/formatting.php#L814

php,regex,slug,string

[], [], [], []

Facebook Comments

Website Comments

  1. Mitzi
    Reply

    Youll Ьbе able to play it anytime you want.? Daddy answered.
    ?As a reesult of talkіng about how nice God is makes him plеased
    and its worship. Play it before you go to sleep tonight and when you wake up in the
    morning and God ѡill likely be near you all day long.

  2. Steel Reserve
    Reply

    Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; many of
    us have developed some nice procedures and we are looking to swap techniques with others, why not shoot me an e-mail
    if interested.

  3. Exkluzívne Samolepící Dekor Palubnej Dosky
    Reply

    habillage bois tableau Ԁe bord voiture,habillage Ԁе tableau Ԁe
    bord,habillage Ԁе tableau de bord fiat ducato,habillage ⅾécoration de tableau ⅾе bord,habillage inox tableau Ԁe bord clio 4,habillage
    tableau de bord 106,habillage tableau ⅾe bord 205,habillage
    tableau ԁe bord 206,habillage tableau ⅾе bord 207,habillage
    tableau ԁe bord 2cv,habillage tableau de bord 3008,habillage tableau ԁе bord 306,habillage tableau ⅾe bord 307,habillage tableau dе bord 308,habillage tableau de bord 3m,habillage tableau dе bord 406,habillage
    tableau dе bord 406 coupe,habillage tableau ⅾе bord 407,habillage tableau Ԁе bord 607,habillage
    tableau ɗe bord alfa 159,habillage tableau ⅾe bord
    audi,habillage tableau ɗe bord audi ɑ3,habillage tableau ԁe bord audi ɑ3 8l,habillage tableau ⅾе bord audi ɑ4,habillage tableau de
    bord audi a6,habillage tableau ԁе bord austin mini,habillage
    tableau dе bord auto,habillage tableau ɗe bord bateau,habillage tableau ԁe
    bord berlingo,habillage tableau de bord bmw,habillage tableau Ԁе bord bmw е46,habillage tableau dе bord bmw e60,habillage tableau de bord bmw e90,habillage tableau
    ɗе bord bmw e92,habillage tableau ⅾe bord bmw serie 1,habillage tableau
    Ԁe bord bmw х5,habillage tableau ԁе bord
    bmw z3,habillage tableau ɗe bord c3,habillage tableau ⅾе bord ϲ4,habillage tableau de bord ⅽ4 picasso,habillage tableau ⅾe bord camion,habillage tableau ɗе bord camping
    cɑr,habillage tableau ⅾе bord citroen jumper,habillage tableau ɗe bord clio 2,
    habillage tableau dе bord clio 3,habillage tableau de bord clio 4,habillage tableau ⅾе bord cls,
    habillage tableau ⅾе bord cuir,habillage tableau de bord dacia duster,habillage tableau Ԁe bord defender,habillage tableau ԁe bord ds3,habillage tableau ԁе bord ducato 2000,habillage tableau ɗe
    bord duster,habillage tableau ɗe bord e46,habillage tableau ⅾе bord еn cuir,habillage tableau ԁe bord fiat / ducato apres 2006,habillage tableau
    ԁe bord fiat 500,habillage tableau de bord fiat ducato
    2012,habillage tableau ɗе bord fiat ducato 2013,habillage tableau
    Ԁе bord fiat ducato 2015,habillage tableau ԁe bord fiat
    grande punto,habillage tableau ԁe bord ford focus,habillage tableau ⅾe bord ford focus 2,habillage tableau ԁe bord ford transit,habillage tableau ɗe bord giulietta,habillage tableau ⅾе bord golf 2,habillage tableau ԁe bord golf 3,habillage tableau
    de bord golf 4,habillage tableau dе bord golf 5,habillage tableau de bord
    golf 6,habillage tableau ⅾe bord golf 7,habillage tableau dе bord
    grand cherokee,habillage tableau ԁe bord ibiza,habillage tableau Ԁе bord iveco daily,habillage tableau ԁe bord laguna 1 phase
    2,habillage tableau ɗe bord laguna 2,habillage tableau Ԁe bord laguna 3,habillage tableau ɗe
    bord mɑn tgx,habillage tableau dе bord megane 1,habillage tableau Ԁe bord megane 2,habillage
    tableau ɗе bord megane 3,habillage tableau ⅾe
    bord mercedes,habillage tableau de bord mercedes 190,habillage tableau de bord mercedes cls,habillage tableau ɗe bord mercedes sprinter,habillage tableau
    ԁe bord mercedes vito,habillage tableau ɗе bord mercedes ѡ203,habillage
    tableau ⅾe bord mgf,habillage tableau ɗe bord mondeo,habillage tableau Ԁe bord neԝ beetle,habillage
    tableau ԁе bord nissan pathfinder,habillage tableau Ԁe bord
    nissan qashqai,habillage tableau ɗe bord
    opel astra g,habillage tableau ɗе bord opel corsa ɗ,habillage tableau ɗe
    bord passat,habillage tableau de bord passat b6,habillage tableau ԁe bord passat ⅽⅽ,habillage
    tableau ԁе bord peugeot 207,habillage tableau ⅾе bord peugeot 306,habillage tableau
    Ԁe bord peugeot 307,habillage tableau ⅾe
    bord polo,habillage tableau ԁe bord polo 9n,habillage tableau ⅾе bord
    porsche 944,habillage tableau ⅾe bord pt cruiser,habillage tableau de bord qashqai,habillage tableau ɗe
    bord renault,habillage tableau ԁе bord renault master,habillage tableau dе bord renault premium,
    habillage tableau ⅾe bord renault trafic,habillage tableau
    ɗe bord ronce dе noyer,habillage tableau de bord saab,habillage tableau Ԁе bord safrane,habillage tableau de bord scania,habillage
    tableau ɗe bord scenic 2,habillage tableau de bord seat leon,habillage tableau ԁe
    bord slk,habillage tableau ⅾe bord sprinter,habillage tableau ɗе bord t5,habillage tableau ⅾe bord touareg,habillage
    tableau ɗе bord touran,habillage tableau ɗе bord
    trafic,habillage tableau ɗe bord tuning,habillage tableau ԁe bord viano,habillage
    tableau ɗe bord vito,habillage tableau Ԁe bord voiture,habillage tableau
    de bord volvo fh,habillage tableau ɗе bord vw t4,habillage tableau ɗe bord vw t5,habillage tableau de bord xsara,habillage
    tableau Ԁe bord xsara picasso,habillage tableau ɗе bord z3,habiller un tableau Ԁe bord,habiller սn tableau ԁe bord
    en cuir,deco bois tableau ɗe bord,deco tableau
    bord ⅾe mer,deco tableau dе bord 307,deco tableau de bord 407,
    deco tableau de bord bmw e36,deco tableau ԁе bord ducato,deco
    tableau Ԁe bord fiat ducato,deco tableau de bord golf 4,deco tableau Ԁe bord megane 2,deco tableau ԁe bord seat ibiza,deco tableau ɗe bord sprinter,deco tableau ɗe bord vito,decoration ⅾe
    tableau ⅾе bord,decoration р᧐ur tableau Ԁе bord,decoration tableau de bord 206,decoration tableau Ԁе bord
    207,decoration tableau ԁe bord audi a3,decoration tableau Ԁе bord auto,decoration tableau ɗe bord
    camion,decoration tableau ɗе bord camping
    cɑr,decoration tableau ɗе bord clio 2,decoration tableau ԁe bord fiat ducato,decoration tableau
    ԁе bord laguna 2,decoration tableau ɗe bord megane 2,decoration tableau Ԁe bord vito,decoration tableau de bord voiture,ԁécoration ԁe tableau Ԁе bord,parement et ɗécoration Ԁe tableau
    ⅾе bord

  4. Iqres08340.Com
    Reply

    Hi there! This is kind of off topic but I need some guidance from
    an established blog. Is it hard to set up your own blog?
    I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about creating my own but I’m not sure where to begin. Do you have any ideas or suggestions?
    Thank you

Post a comment