mjahkoh Posted August 29, 2011 Share Posted August 29, 2011 I got the below Div. I gather i got the following subtitles in the div (sometimes not all) $subtitle = array('Postal Address:','Street:','Town :','Telephone:','Mobile:','Contact Person:','Country:','e-mail:','Website:'); It occurs that the title is enclosed in font tag and the title text is what follows after the closing </font> upto the next <br>; Please help on retrieving The Title and the text. Regards <div align="left" id="tabledetails__"><font color="#4E779F" size="+1">Beverages Ltd</font><br> <font color="brown">Postal Address: </font>1604120 <br> <font color="brown">Street: </font>Karatina Town Council <br> <font color="brown">Town :</font>Kampala <br> <font color="brown">Telephone: </font>+254 414 983456 <br> <font color="brown"> Country: </font>Kenya <br> <font color="brown">e-mail: </font><a href="mailto:[email protected]">[email protected]</a> </div> Link to comment https://forums.phpfreaks.com/topic/245950-string-parsing/ Share on other sites More sharing options...
silkfire Posted August 29, 2011 Share Posted August 29, 2011 You can use either a DOM parser or a Regex method. Regex method: preg_match_all('#<font[^>]+>([^<]+).*?>(?:<a.*?>)?([^<]+)#', $div, $matches, PREG_SET_ORDER); The matches array will look something like this: Array ( [0] => Array ( [0] => <font color="#4E779F" size="+1">Beverages Ltd</font><br> [1] => Beverages Ltd [2] => ) [1] => Array ( [0] => <font color="brown">Postal Address: </font>1604120 [1] => Postal Address: [2] => 1604120 ) [2] => Array ( [0] => <font color="brown">Street: </font>Karatina Town Council [1] => Street: [2] => Karatina Town Council ) [3] => Array ( [0] => <font color="brown">Town :</font>Kampala [1] => Town : [2] => Kampala ) [4] => Array ( [0] => <font color="brown">Telephone: </font>+254 414 983456 [1] => Telephone: [2] => +254 414 983456 ) [5] => Array ( [0] => <font color="brown"> Country: </font>Kenya [1] => Country: [2] => Kenya ) [6] => Array ( [0] => <font color="brown">e-mail: </font><a href="mailto:[email protected]">[email protected] [1] => e-mail: [2] => [email protected] ) ) Link to comment https://forums.phpfreaks.com/topic/245950-string-parsing/#findComment-1263134 Share on other sites More sharing options...
mjahkoh Posted August 29, 2011 Author Share Posted August 29, 2011 Silkfire. Please attach your matches variable. This will get me home. Regards Link to comment https://forums.phpfreaks.com/topic/245950-string-parsing/#findComment-1263138 Share on other sites More sharing options...
silkfire Posted August 29, 2011 Share Posted August 29, 2011 What do you mean? Run the code I gave you. $div is a string with the HTML structure. Link to comment https://forums.phpfreaks.com/topic/245950-string-parsing/#findComment-1263145 Share on other sites More sharing options...
AyKay47 Posted August 29, 2011 Share Posted August 29, 2011 silkfire already provided what the $matches variables will output Link to comment https://forums.phpfreaks.com/topic/245950-string-parsing/#findComment-1263147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.