SadDemon Posted July 3, 2007 Report Share Posted July 3, 2007 *.xml saturs ir: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <Noliktava produkcijai="----"> <product id="1" amount="2" name="test" color="test" article="-" category="citi" status="ir" catalog="test" page="-" price="-" /> <product id="2" amount="7" name="vizītkaršu etvija" color="metāls" article="50042" category="birojam" status="ir" catalog="Reflect" page="87" price="2.64" /> <product id="3" amount="25" name="vizītkaršu etvija" color="metāls" article="ap802301" category="birojam" status="ir" catalog="Anda Present" page="39" price="1.16" /> <product id="4" amount="127" name="vizītkaršu etvija" color="metāls" article="1602270" category="birojam" status="ir" catalog="Marksmans (vecais)" page="-" price="2.19" /> </Noliktava> un *.php saturs ir: <?php $amount_input = '2'; $name_input = ''; $category_input = ''; $status_input =''; $doc = new DOMDocument; $doc -> load('../xml/depot.xml'); $content = array(); $products = $doc -> getElementsByTagName('product'); foreach ($products as $product) { $id = $product -> getAttribute('id'); $amount = $product -> getAttribute('amount'); $name = $product -> getAttribute('name'); $color = $product -> getAttribute('color'); $article = $product -> getAttribute('article'); $category = $product -> getAttribute('category'); $status = $product -> getAttribute('status'); if(ereg($amount_input, $amount)) { $row = "<"."product id=\"".$id."\" amount=\"".$amount."\" name=\"".$name."\" color=\"".$color."\" article=\"".$article."\" category=\"".$category."\" status=\"".$status."\" />"."<br>"; $content[$id] = $row; } } ksort($content); foreach ($content as $output) { echo $output; } ?> Problēma Nr.1 - ja meklējamais ir "2" starp amount atribūtiem, tad atrodam.. "2", "25" un "127".. bet nepieciešams ir tikai "2" un "25".. tobiš, lai meklētu tikai no pirmā simbola.. Problēma Nr.2 - vajadzētu panākt, lai.. ja $amount_input nav tukš un pārējie ir, tad "ereg($amount_input, $amount)".. ja $amount_input nav tukš un, piemēram, $category_input nav tukš.. tad "(ereg($amount_input, $amount) && ereg($category_input, $category))".. Iepriekš pateicos par palīdzību! Link to comment Share on other sites More sharing options...
Val Posted July 3, 2007 Report Share Posted July 3, 2007 (edited) 1. es ir dumš ar tiem te, bet varbūt šādi? $amount_input = '^[2]'; Edited July 3, 2007 by Val Link to comment Share on other sites More sharing options...
v3rb0 Posted July 3, 2007 Report Share Posted July 3, 2007 ja tas ko gribi panākt, ir meklēt pēc "sākot ar..", tad tur pat regex nevajag - strpos($amount , '2') === 0 Link to comment Share on other sites More sharing options...
Recommended Posts