plznty Posted December 21, 2010 Share Posted December 21, 2010 information.txt <li><img src="http://www.lol.com" alt="0" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="4" /></li> <li><img src="http://www.lol.com" alt="9" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="7" /></li> <li><img src="http://www.lol.com" alt="2" /></li> How can I get the alt="$ValueIwant" for each with a preg_match Quote Link to comment https://forums.phpfreaks.com/topic/222341-preg_match-how-can-i/ Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 something like... $string = file_get_contents("information.txt"); $pattern = '/alt="(.*)" \//'; preg_match_all($pattern, $string, $matches); print_r($matches); Quote Link to comment https://forums.phpfreaks.com/topic/222341-preg_match-how-can-i/#findComment-1150103 Share on other sites More sharing options...
plznty Posted December 22, 2010 Author Share Posted December 22, 2010 How would I print one by one? Quote Link to comment https://forums.phpfreaks.com/topic/222341-preg_match-how-can-i/#findComment-1150135 Share on other sites More sharing options...
BlueSkyIS Posted December 22, 2010 Share Posted December 22, 2010 $matches contains an array of each one. one by one. loop over the appropriate part of $matches to get each value, one by one. Quote Link to comment https://forums.phpfreaks.com/topic/222341-preg_match-how-can-i/#findComment-1150147 Share on other sites More sharing options...
dreamwest Posted December 22, 2010 Share Posted December 22, 2010 Another example: $str = file_get_contents("information.txt"); preg_match_all('~alt\s?=\s?[\'"](.*?)[\'"]~is', $str, $a); foreach ($a[1] as $c) { echo "{$c} <br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/222341-preg_match-how-can-i/#findComment-1150170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.