jjmusicpro Posted December 8, 2010 Share Posted December 8, 2010 I have this in the html: <div class="c"><strong>Joes Cool Name</strong></div> I am trying to use preg_match to just get "Joes Cool Name" out of it, but keep getting blank values... Here is what I have..thanks for any help guys... im new to preg_match function preg_match('/<div class=\"c\">([^\<]*)<\/div>/i', $result, $name); Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/ Share on other sites More sharing options...
sasa Posted December 8, 2010 Share Posted December 8, 2010 try preg_match('/<div class=\"c\">(.*?)<\/div>/i', $result, $name); Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144596 Share on other sites More sharing options...
jjmusicpro Posted December 8, 2010 Author Share Posted December 8, 2010 That also gets the <strong></strong>, and i dont want that Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144616 Share on other sites More sharing options...
jjmusicpro Posted December 8, 2010 Author Share Posted December 8, 2010 To get rid of the <strong></strong> i just did a str_replace... but i assume there is better way to do this? Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144658 Share on other sites More sharing options...
mikecampbell Posted December 8, 2010 Share Posted December 8, 2010 Just modify sasa's regex a bit... preg_match('/<div class=\"c\"><strong>(.*?)<\/strong><\/div>/i', $result, $name); Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144659 Share on other sites More sharing options...
jjmusicpro Posted December 8, 2010 Author Share Posted December 8, 2010 Ok cool, here is one i tried doing myself, but having same problems. HTML - <div class="mfsm">Email:</div></td><td valign="top"><div class="mfsm"><a href="mailto:Array">[email protected]</a></div> Here is what i have, but its blank.. preg_match('|mail([^\<]*)<\/div><\/td><td valign=\"top\"><div class=\"mfsm\">([^\<]*)<|', $result, $email); Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144669 Share on other sites More sharing options...
jjmusicpro Posted December 8, 2010 Author Share Posted December 8, 2010 Is my ([^\<]*) is whats messing it up? Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144676 Share on other sites More sharing options...
jjmusicpro Posted December 8, 2010 Author Share Posted December 8, 2010 ? Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144707 Share on other sites More sharing options...
jjmusicpro Posted December 9, 2010 Author Share Posted December 9, 2010 anyone ? Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144755 Share on other sites More sharing options...
sasa Posted December 9, 2010 Share Posted December 9, 2010 preg_match('|href="mailto:([^"]*)"|', $result, $email); Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144797 Share on other sites More sharing options...
jjmusicpro Posted December 9, 2010 Author Share Posted December 9, 2010 When i try that above i get a wrong kick out. preg_match('|href="mailto:([^"]*)"|', $result, $email); echo $email[0]. " " .$email[1]. " " . $email[2]; Kick out below .href="mailto:Array" Array .href="mailto:Array" Array Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144802 Share on other sites More sharing options...
sasa Posted December 9, 2010 Share Posted December 9, 2010 and what you want to mach Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144805 Share on other sites More sharing options...
jjmusicpro Posted December 9, 2010 Author Share Posted December 9, 2010 So if i have <div class="mfsm">Email:</div></td><td valign="top"><div class="mfsm"><a href="mailto:Array">[email protected]</a></div> I want it to give me anything within the <div class="mfsm"></div> Now sometimes there might be an image in there like <div class="mfsm"><img src="/something/joe.jpg"></div> so i want that full thing "<img src="/something/joe.jpg">" thats what my reg exp tried to do before. Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144806 Share on other sites More sharing options...
jjmusicpro Posted December 9, 2010 Author Share Posted December 9, 2010 keep in mind there are multiple <div class="mfsm"></div> on the page...thats why i couldnt look through it directlyl. Link to comment https://forums.phpfreaks.com/topic/221053-help-with-preg_match-function/#findComment-1144807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.