[TUT] Data on Images

Posts 1–10 of 10 · Page 1 of 1
[TUT] Data on Images
Hey everyone, I thought I would stray from the VB for awhile, and teach something new and cool. Its called Script Scrapping, then adding them to GD Imaging. Very simple, and Ill explain.

We are making this, an image that will show how many Thanks I have. If you thank me, you will see the images number changes:


Since this is PHP we need to start off with our brackets.

Code:
<?php

?>
Now, adding the code inside it. I will give you the full code then explain each part.

Code:
<?php
$url = "http://www.mpgh.net/forum/33-visual-basics/83177-real-vb-injecter-source-code.html";

$data = file_get_contents($url);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
$content = str_replace($newlines, "", html_entity_decode($data));

$html = '/Thanked (.+?) Times/';
preg_match($html,$content,$thanks);

var_dump($thanks);
echo $thanks[1];

//echo "<br>";
//echo $content;

?>

$url = "http://www.mpgh.net/forum/33-visual-basics/83177-real-vb-injecter-source-code.html";
Here we are making the URL that we are getting the source code from, is a thread I made. I chose a thread because the php is visiting the page as a guest, so I cant make it go to my profile.

$data = file_get_contents($url);
Here I am saying "Hey URL, give me your contents, and then name those contents $data".

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
I decided to remove afew stuff I didnt need, and to make it easier for me, so I decided to remove all New Lines, as well as /,(,),<,>.

$content = str_replace($newlines, "", html_entity_decode($data));
Here I am telling the $data to replace everything we put earlier in $newlines, with "", meaning it just removes them. Now $data has turned to $content.


$html = '/Thanked (.+?) Times/';
Here I am making $html = to a string that will be found later. It is required you have the /content/ dashes in there. (.+?) stands for what we want. So it would normally be "Thanked 10 Times", I replace the number with (.+?), because the number is what I want to pull.

preg_match($html,$content,$thanks);
Here we are telling it to match (find) $html, with $content, then name it $thanks.

var_dump($thanks);
Var dump isnt much needed, so what you can do after this test, is change it to
Code:
//var_dump($thanks);
But this is good to see if your data is even there, With this code It will output
array(2) { [0]=> string(16) "Thanked 43 Times" [1]=> string(2) "43" }
And as you can see, you have 2 options. You can use
$thanks[0] for Thanked 43 Times
or
$thanks[1] for 43

SO we want $thanks[1].

Thats where the ending comes in

echo $thanks[1];
This will make the number show, as text.

//echo "<br>";
//echo $content;

This you can leave alone, but if you ever want to see the content then remove the "//" infront of both.



Next Step
Now that we have the variable we are looking for, we need to change up the code abit. We now change it to this.

Code:
<?php
header("Content-type: image/png");
$url = "http://www.mpgh.net/forum/33-visual-basics/83177-real-vb-injecter-source-code.html";
$data = file_get_contents($url);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
$content = str_replace($newlines, "", html_entity_decode($data));
$html = '/Thanked (.+?) Times/';
preg_match($html,$content,$thanks);
?>
And after you change it to this, now we need to add the imaging that needs to be done.
SO now your full code should look like this.

Code:
<?php
header ("Content-type: image/png");
$url = "http://www.mpgh.net/forum/33-visual-basics/83177-real-vb-injecter-source-code.html";

$data = file_get_contents($url);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
$content = str_replace($newlines, "", html_entity_decode($data));
$html = '/Thanked (.+?) Times/';
preg_match($html,$content,$thanks);

$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 0, 0);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageString ($handle, 5, 5, 18, "Thanks: $thanks[1]", $txt_color);
ImagePng ($handle);
?>
And this code will produce


For it to work on you, find a thread that was started by yourself, and change the $url to your threads URL.
nice work on this
np, once you learn this, sooner or later ud be making this:

Hey wow this is pretty cool stuff. I'll have to stick around here a little more often.

Oh and thanks Ugleh.
Code:
<?php
header ("Content-type: image/png");
$url = "http://www.mpgh.net/forum/198-php-html/84620-tut-data-images.html";

$data = file_get_contents($url);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
$content = str_replace($newlines, "", html_entity_decode($data));
$html = '/Thanked (.+?) Times/';
preg_match($html,$content,$thanks);

$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 0, 255, 0);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageString ($handle, 5, 5, 18, "Thanks: $thanks[1]", $txt_color);
ImagePng ($handle);
?>
Damit html is off D:

Ok one question:

How does this make $thanks into an array?
Code:
array(2) { [0]=> string(16) "Thanked 43 Times" [1]=> string(2) "43" }
shouldn't it be something like this:
Code:
$thanks(2) { [0]=> string(16) "Thanked 43 Times" [1]=> string(2) "43" }
I'm just a little confused at the way you assigned it a value. It looks nothing like that in C++. But I am willing to learn please explain

Could you explain more what all these symbols remove.
Code:
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
If I need to learn some other stuff first point me in the right direction and I will go there.
the Var_dump already calls for $thanks, so it just outputs an array. and it tells you there is 2. the $thanks[0] and $thanks[1].

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B","/","(", ")",">","<" );
This will remove

\t
\n
\r
\x20\x20

In some coding (in php too) you use \n or \r to represent a new line.
I also added
<>
()
/
Because with those removed I will not get any errors when grabbing values.
Ok. Thanks for the quick reply.

Now what about all the other words. Because it seems to me you would get a really huge array of words and numbers. How do you narrow it down to the two that you want?

Oh wait I get it! This finds the right string your looking for:
$html = '/Thanked (.+?) Times/';
preg_match($html,$content,$thanks);


Sweet thanks a lot. Ugleh
no problem, remember what has been removed though, if you ever need to look at the content remove the // infront of echo $content

then do Ctrl + F to find the current data, and copy stuff around it, and replace the number or word with (.+?)

Make sure you have the "/"s like > /Content(.+?) secondcont/
I knew it but thanks !
So what do we make this in?? And what do we save it as??
lol, this is the php forum, so it would be a .php file, using notepad. Then you upload it to a web server.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Need help?