tags:

views:

21

answers:

2

Having a major brain freeze, I have the following chunk of code:

// Get web address
$domQuery = query_HtmlDocument($html, '//a[@class="productLink"]');

    foreach($domQuery as $rtn) {
    $web = $rtn->getAttribute('href');
    }

Which obviously gets the entire href attribute, however I only want 1 specific attribute within the href. I.e. If the href is: /website/product1234.do?code=1234&version=1.3&somethingelse=blaah

I only want to return the variable for "version", so wish to only return "1.3" in my example. What's most efficient way to do this?

+2  A: 

You could use parse_url and parse_str to extract that information.

webdestroya
A: 

Bingo! Thanks webdestroya, parse_str is exactly what I am after:

$string="/website/product1234.do?code=1234&version=1.3&somethingelse=blaah";
parse_str($string,$return);

$version = $return['version'];

echo "Version: " . $version;

Prints:

Version: 1.3
Michael Pasqualone
Sweet! Glad it worked for you
webdestroya