jmahdi Posted March 6, 2012 Share Posted March 6, 2012 what is the best way yo do this? <b><font color=green>Get me out please </font> . </b> thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/ Share on other sites More sharing options...
jmahdi Posted March 6, 2012 Author Share Posted March 6, 2012 i need to use php as the html codes are kept in database fields and i need to go through them and pull wanted data... Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324406 Share on other sites More sharing options...
jmahdi Posted March 6, 2012 Author Share Posted March 6, 2012 hello Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324432 Share on other sites More sharing options...
scootstah Posted March 6, 2012 Share Posted March 6, 2012 Regular expressions. <?php $str = '<b><font color=green>Get me out please </font>.</b>'; $pattern = '/<font[^>.]*>(.*)<\/font>/i'; if (preg_match($pattern, $str, $matches)) { echo $matches[1]; // Get me out please } Also, don't bump your threads after 2 hours. 17. Users should not "bump" topics that are still on the first page of the forums. If you bump, you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described (see Eric Raymond's "How To Ask Questions The Smart Way") Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324434 Share on other sites More sharing options...
jmahdi Posted March 6, 2012 Author Share Posted March 6, 2012 thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324443 Share on other sites More sharing options...
jmahdi Posted March 6, 2012 Author Share Posted March 6, 2012 Regular expressions. <?php $str = '<b><font color=green>Get me out please </font>.</b>'; $pattern = '/<font[^>.]*>(.*)<\/font>/i'; if (preg_match($pattern, $str, $matches)) { echo $matches[1]; // Get me out please } what if its more than one font tag like: <b><font color=green>Get me out please </font></b><a><font color=green>Get me out please </font></a> how to utilise forforeach or for loops and can i still stick to the same regular expression....thanks thanks Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324479 Share on other sites More sharing options...
scootstah Posted March 6, 2012 Share Posted March 6, 2012 Disregard the pattern in my first post, this one will work a lot better: $str = '<b><font color=green>Get me out please </font></b><a><font color=green>Get me out please </font></a>'; $pattern = '/<font.*?>(.*?)<\/font>/i'; if (preg_match_all($pattern, $str, $matches)) { print_r($matches[1]); /* Array ( [0] => Get me out please [1] => Get me out please ) */ } Using preg_match_all will grab values in multiple font tags. Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324544 Share on other sites More sharing options...
jmahdi Posted March 7, 2012 Author Share Posted March 7, 2012 Thanks a bunch...take care Quote Link to comment https://forums.phpfreaks.com/topic/258371-pulling-innerhtml-data-from-html-code/#findComment-1324800 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.