karthikeyan_coder Posted October 29, 2007 Share Posted October 29, 2007 Hello, I have this text. $string = "blab blab some useless html tags here <strong>Downloads:</strong> 1,826 </p> and some other "; I need to get number of downloads only. I have no guess about this. how to fetch the data the resides between "Downloads:</strong>" and </p> Note: that page may have too many "Downloads" words and </strong> tags. so "Downloads:</strong>" would be a best initial needle for fetching.. Help me please. Link to comment https://forums.phpfreaks.com/topic/75244-smart-help-needed/ Share on other sites More sharing options...
severndigital Posted October 29, 2007 Share Posted October 29, 2007 you could do something like this, my first attempt anyway $string = "blab blab some useless html tags here <strong>Downloads:</strong> 1,826 </p> and some other "; $var = explode(":",$string); //this will split the string into two pieces. $downloads = substr($var[1],9,4); //go out 9 chars and take the next 4 question, how are you getting the download count initially? can the grab be done prior to display? Link to comment https://forums.phpfreaks.com/topic/75244-smart-help-needed/#findComment-380568 Share on other sites More sharing options...
sasa Posted October 29, 2007 Share Posted October 29, 2007 try <?php $a = '$string = "blab blab some useless html tags here <strong>Downloads:</strong> 1,826 </p> and some other ";'; preg_match('/Downloads:<\/strong>(.*)<\/p>/s', $a, $b); echo $b = preg_replace('/[^0-9]/', '', $b[1]); ?> Link to comment https://forums.phpfreaks.com/topic/75244-smart-help-needed/#findComment-380581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.