Jump to content

cURL getting specific info from page. Simple. pls help!


daydreamer

Recommended Posts

I want to be able to retrieve how many texts I have left so I can use it as a variable in my code.

 

On the 02 website, it says "You have X texts remaining".

 

How can I retrieve number X?

 

The html code on the 02 site containing this number:

 

<div style="width: 70%; float: left;">
<div style="float: left;">
</div>
<div style="padding: 3px 0pt 0pt 5px; float: left;">
<label title="Use free text. 6 remaining" for="compose.paymentType" style=""> Use free text. You have 6 texts remaining </label>
</div>
</div>
</div>

 

I have already used cURL at this point in my script, so this page will be loaded on my server cURL session. Just need advice on how I can use PHP code to retrieve this number.

 

Any help appreciated - Thanks!  ;D

 

 

 

Link to comment
Share on other sites

Find it with a regular expression.

 

E.G

 

<?php
$string = <<<EOF

<div style="width: 70%; float: left;">
<div style="float: left;">
</div>
<div style="padding: 3px 0pt 0pt 5px; float: left;">
<label title="Use free text. 6 remaining" for="compose.paymentType" style=""> Use free text. You have 6 texts remaining </label>
</div>
</div>
</div>

EOF;


preg_match("/(?<=You have )[0-9]+/",$string,$matches);
print_r($matches);
?>

 

Link to comment
Share on other sites

I am using Curl and PHP to log into a SMS mobile phone texting site (02.co.uk), which gives you 10 free texts a month.

 

On the compose text page, it will display how many free texts you have remaining for this month. I want to be able to get this number and store it in a variable in my code. My first post shows where exactly in HTML code on the 02 site the number is. Let me know if you need more details.

 

This is how im using curl (excluding cookies and other connection settings):

 

curl_setopt($curl, CURLOPT_URL, "http://sendtxt.o2.co.uk/sendtxt/action/compose"); //go to compose page 
$xxx = curl_exec($curl); // execute above, save page in $xxx
curl_close ($curl);   // close curl session
echo $xxx;     // output compose page

 

So the page is stored in $xxx. I need to get the number from this page.

 

Hey KrisNz, I tried your example, but this is what I got when run:

 Use free text. You have 6 texts remaining
EOF; preg_match("/(?<=You have )[0-9]+/",$string,$matches); print_r($matches); ?>

 

What are the EOF tags you use? "End Of File"?

 

But thanks for the example, I am going to look up more about the preg_match function!

 

 

 

Link to comment
Share on other sites

Oops.

 

KrisNz your code returns:

Array ( [0] => 6 )

 

just what I needed thanks! I was not going through my apache server to read the file.

 

Ok. So this is what I am using:

 

preg_match("/(?<=You have )[0-9]+/",$xxx,$matches);
echo "Number of free texts left: ";
echo $matches[0];  // output array position 0 - number of free texts

 

It works fine 8). But...

 

What do all the slashes and symbols mean in this part of the code:

 

("/(?<=You have )[0-9]+/",

 

And also, the text messages will start off from 10. So will the [0-9] part work? I tried to change the 9 to a 10, but I get 0 outputted, can you explain this to me?

 

thanks!

 

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.