Helpful Information
 
 
Category: Regex Programming
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.

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.

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.

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!










privacy (GDPR)