Return specific HREF attribute using Xpath query
Posted
by Michael Pasqualone
on Stack Overflow
See other posts from Stack Overflow
or by Michael Pasqualone
Published on 2010-06-01T02:07:00Z
Indexed on
2010/06/01
2:13 UTC
Read the original article
Hit count: 252
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?
© Stack Overflow or respective owner