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

    Join Date
    Nov 2007
    Posts
    114
    Rep Power
    27

    Cool Search content in string between two separators


    Hello,

    I am looking to fetch the data between two xml tags.

    xml Code:
     
    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <userName>Agri</userName>


    I would like to fetch "Agri" from the above, unfortunately my server does not have any PHP xml parsers like SimpleXML installed, can this be achieved with regex?

    Cheers,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Location
    Galveston, TX
    Posts
    50
    Rep Power
    8
    Yes, but it would be quite cumbersome writing regex every time you want to do so. You would be better downloading a little library from somewhere if your host won't enable the module for you.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You should have posted this in the regexp forum:
    PHP Code:
    preg_match("/<userName>([^<]+)/"$xml$foo);
    echo 
    "Username is {$foo[1]}\n"
    If you have further questions, use the regexp forum.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo