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

    Join Date
    Mar 2010
    Posts
    38
    Rep Power
    5

    Sub string for q


    hello,
    I getting url string, for example:
    http://www.google.com/#hl=en&source=hp&q=php&aq=f&aqi=g10&aql=&oq=&gs_rfai=&pbx=1&fp=93c3c78db929eee0

    How can I get into variable the string between "&q" and "&" (in this example it's: "php"

    ?

    Thank you in advance,
    Roi
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    38
    Rep Power
    5
    Ok, someone helped me.
    Here it is if someone else gonna need it:

    PHP Code:
    $url =   'http://www.google.com/#hl=en&source=hp&q=php&aq=f&aqi=g10&aql=&oq=&gs_rfai=&pbx=1&fp=93c3c78db929eee0';
    preg_match("/\&q=(.*?)\&/"$url$matches);

    $str $matches[1]; 
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Avoid regular expressions when there are existing functions that can do what you need.

IMN logo majestic logo threadwatch logo seochat tools logo