开发者

xpath php sort attribute based on greater than date

开发者 https://www.devze.com 2023-01-09 02:22 出处:网络
Need to xpath xml data based on greater than date attribute. The dashes in the date below prevent the greater than symbol from working. Is there a way to remove the dash开发者_开发技巧es in the xml on

Need to xpath xml data based on greater than date attribute. The dashes in the date below prevent the greater than symbol from working. Is there a way to remove the dash开发者_开发技巧es in the xml on the fly?

XML

<revisions>
  <revision date="2010-07-12">blah</revision>
  <revision date="2010-06-12">blah</revision>
</revisions>

PHP

$rdate = 2010-07-01;
$programs = $item->xpath("/programs/program[revisions/revision[@date>'".$rdate."']]");


You might try:

$rdate = 20100701;

/programs/program[revisions/revision[translate(@date,'-','') > '20100701']

Edit: one should note that in XPath 2.0 the compare() function is available (-1 smaller, 0 equal, 1 higher), so you can just compare strings. As far is I know most PHP implementations are still using XPath 1.0 though.


http://php.net/manual/en/function.str-replace.php

str_replace($date, '-', '')
0

精彩评论

暂无评论...
验证码 换一张
取 消