Domanda

I'm trying to get values like these color="#7fff00", color="#bfffff", etc from file using preg_match_all:

preg_match_all( '/\bcolor=([a-f ]*)/', $data, $mc);

but all I get is color= and thats all.. I'm not sure Im doing it right.. Probably not.. Can anyone explain to me how to search for word COLOR= and everything that follows after that word? Thnaks

È stato utile?

Soluzione

You're not matching the quotes or # character in the string. Change your pattern to:

preg_match_all('/\bcolor="([#a-f]*)"/i', $data, $mc);

But depending on what you're trying to parse, a regex might not be the best tool. If you're trying to parse HTML, it's always best to use an HTML parser.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top