#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    52
    Rep Power
    6

    Php extract substring from between single quote marks


    Hi, I'm sure this is very simple, but I'm afraid I've had a look around and can't find the answer so I was hoping someone here could help.

    I have a string

    "'The name' and a bit of description"

    which I am pulling from a mysql query. I want to extract:

    The name

    using php. I'm sure it's a simple regular expression, but can't work it out, could someone help me out?

    Many thanks!
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    Try using this expression:
    Code:
    '/(?<=\s)\'([^\']+)\'(?=\s)/'
    P.S. Why did you post this in the web design forum? (I already moved it to the Regex forum.)
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo