Hello im trying to manipulate the text after expression with XPATH and PHP, but do not work.
->query('//th[contains(., "Code")]/following-sibling::*[1]')
Result:
111,222,333
Expected :
222,333
Or perfect would have this exploded in array for further manipulation
[111]
[222]
[333]
I've been tried this without success:
->query('//th[contains(., "Code")]/following-sibling::*[substring-after(.,",")]')
->query('substring-after(/th[contains(., "Code")]/following-sibling::*[1],",")')
->query('//th[contains(., "Code")]/substring-after(/following-sibling::*[1],",")')
Any help to fix this please? Many Thanks
That must work for you
substring-after(/tr/th[.='Code']/following-sibling::td, ',')
Minor improvement which you may need (delete spaces before and after)
normalize-space(substring-after(/tr/th[.='Code']/following-sibling::td, ','))
Your xpath expression which using susbstring-after()
function looks promising. But note that DOMXPath::query()
unable to return other than node-set. For executing xpath expression that doesn't return node-set, i.e substring-after()
function, use DOMXPath::evaluate()
instead :
$xpath->evaluate('substring-after(//th[contains(., "Code")]/following-sibling::*[1],",")');