ExSpirit Posted November 7, 2010 Share Posted November 7, 2010 I am having problems extracting some "code" with preg_match and I hope someone can help me how to extract the correct "code/word" from html code which looks like this: My code: <b>ss.34-some<img src='http://mydomain.com/images/slash.gif' alt='$'>anothernum.123.word</b> My code: <b>other<img src='http://mydomain.com/images/slash.gif' alt='$'>code.1234.test</b> My code: <b>and.another<img src='http://mydomain.com/images/slash.gif' alt='$'>code</b> ... So from this HTML code I should get this: ss.34-some$anothernum.123.word other$code.1234.test and.another$code If anyone can help me I would really appreciate it. Link to comment https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/ Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 <?php $test = "My code: <b>ss.34-some<img src='http://mydomain.com/images/slash.gif' alt='$'>anothernum.123.word</b> My code: <b>other<img src='http://mydomain.com/images/slash.gif' alt='$'>code.1234.test</b> My code: <b>and.another<img src='http://mydomain.com/images/slash.gif' alt='$'>code</b> ... "; preg_match_all('/<b>[^<]*<img[^>]*alt=\'[^\']*\'[^>]*>[^<]+<\/b>/i', $test, $matches); foreach ($matches[0] as $v){ $out[] = preg_replace('/<b>([^<]*)<img[^>]*alt=\'([^\']*)\'[^>]*>([^<]+)<\/b>/i', '\1\2\3', $v); } print_r($out); ?> Link to comment https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/#findComment-1131660 Share on other sites More sharing options...
ExSpirit Posted November 8, 2010 Author Share Posted November 8, 2010 I would never get this together. sasa you rock Thank you very much, it works great now. Link to comment https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/#findComment-1131766 Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 if it works then mark topic solved Link to comment https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/#findComment-1131828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.