Jump to content

smart help needed


karthikeyan_coder

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.