开发者

PHP XPATH: return character in xpath string

开发者 https://www.devze.com 2023-02-15 22:24 出处:网络
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

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))]

0

精彩评论

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

关注公众号