Having trouble finding the first character of Field42 inside xpath, see below. Any suggestions?
$letters = split(',开发者_Python百科','0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
foreach($letters AS $letter) {
if(count($item->xpath("/Entries/Entry[Field42{0}='".$letter."']")) > 0) {
$entries = $item->xpath("/Entries/Entry[Field42{0}='".$letter."']"); ?>
XML Structure
<Entries>
<Entry>
<EntryId>33</EntryId>
<Field71/>
<Field41>Jane</Field41>
<Field42>Smith</Field42>
You can use XPath's starts-with
function:
$item->xpath("/Entries/Entry[starts-with(Field42,'".$letter."')]")
If you want all Entry
elements starting with a letter from a given string, use:
/Entries/Entry[contains('0123456789abcdefghijklmnopqrstuvwxyz',substring(.,1,1))]
精彩评论