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

    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Regexp question.


    Hello.

    I have a *.ini file that contains some data in a format like this ;

    "username" "password" "somethinghere" "anotherdata"

    I want to read each value between "---" characters with PHP. So I created a pattern like this ;

    preg_match_all("/\"(.*)\"\s+\"(.*)\"\s+\"(.*)\"\s+\"(.*)\"/", $line, $result);

    It simply works but If there is a value contains some special chars like < and > , it does not match them. Example data ;

    "<one> Customer" "34324324" "aaaaaaaaaa" "b"

    When I had printed what I had in $result, I saw only Customer for the first data. <one> part was gone.

    Can someone offer me better pattern?

    Thanks for helps and answers.
  2. #2
  3. No Profile Picture
    Hang your freedom higher.
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2005
    Posts
    659
    Rep Power
    158
    The regular expressions looks like it "should" work for your supplied data, so can you supply functioning code and data that demonstrates this issue working and not working.
    "Badges? We ain't got no badges. We don't need no badges! I don't have to show you any stinkin' badges!!"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    928
    Just a shot in the dark, but are you printing the result to an HTML page? The renderer might be ignoring the <one> as an invalid HTML tag, in which case you should use htmlspecialchars() or htmlentities() to protect the text.

    Comments on this post

    • Viper_SB agrees : yep sounds correct
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0
    Originally Posted by OmegaZero
    Just a shot in the dark, but are you printing the result to an HTML page? The renderer might be ignoring the <one> as an invalid HTML tag, in which case you should use htmlspecialchars() or htmlentities() to protect the text.
    Oh yes! This is exactly what I couldn't think.. I will try, thanks!

IMN logo majestic logo threadwatch logo seochat tools logo