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. Quote 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? Quote 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]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75244-smart-help-needed/#findComment-380581 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.