#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    206
    Rep Power
    10

    Filtering an XML file by a string


    Hi,

    I'm trying to filter an XML file file by a string contained in a node.

    I'm using SimpleXML to do it. However, I can only filter by the exact value of a node, I can't filter by a part of that string. Here i my code:

    Code:
    <all>
    <clothes>
    <item>The big red shoe</item>
    <price>44.99</price>
    </clothes>
    <clothes>
    <item>Small red coat</item>
    <price>4.99</price>
    </clothes>
    </all>
    PHP Code:
      $newresult $result->xpath("//all/clothes/item[.='The big red shoe']/.."); 
    It works only for the specific string 'The big red shoe'. I want to instead show all results that contain the word 'red'.

    Any ideas?

    Many thanks in advance
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    30 seconds using Google:

    contains()
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo