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 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); 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? 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. 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 />"; } 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
Archived
This topic is now archived and is closed to further replies.