
|
View Full Version : from one corner to another
ti_nhatrang 10-04-2006, 06:08 AM Hi guys,
I'm trying to create an intranet that generates zip files on a windows machine and it generates it into a xml/txt file...
it's like this:
http://localhost/files/?=newfiles
and it extracts:
<div id="proborders">
<div class="proborders">
<h2>Download</h2>
</div>
<div class="proborders">
<span id="getfilehere"><b>newfiles</b><br /><br /><table style="BORDER: none; WIDTH: 700px"><tbody><tr><td style="BORDER: none"><p align="left"><a href="http://localhost/Files/%5BFrom%20drived%5D%9874.54314.95.zip"><img src="./vd/botdl.gif" align="middle" border="0" /></a></p></td><td style="BORDER: none; PADDING-LEFT: 5px; WIDTH: 620px"><p align="left">(.zip) Right-click -> "Save Target As" OR copy and paste the link into your download manager. </p></td></tr></tbody></table><br /><div align="right"><a href="#" onclick="javascript:window.close();">[ close window ]</a></div></span>
</div>
</div>
</div>
</body>
</html>
I guess my question is, can you guys help me extra it with another php script that will pick up just http://localhost/Files/%5BFrom%20drived%5D%9874.54314.95.zip, rather than the whole thing?
I've tried fwrite, and it gives me the whole thing... Please help and thank you in advance...
Neoboffin 10-04-2006, 07:05 AM Not sure what you're saying here.
Are you saying that you want to only extract the URL from the file?
ti_nhatrang 10-04-2006, 07:08 AM that's correct, I only want to grab that portion when I run that url:http://localhost/files/?=newfiles
Neoboffin 10-04-2006, 07:39 AM The PHP function ereg will help you.
http://uk.php.net/function.ereg
ti_nhatrang 10-04-2006, 08:41 AM I still do not understand after reading it, please help me with samples from my current work...
jobinma 10-04-2006, 09:57 AM I won't do it for you because it won't help you to progress in php.
But, what I can tell you is that when you read this file and have all the content in a variable, here is what you can do :
- Use the strpos function and try to find the position of 'http' which, in your example, appears only once so it shouldn't be that hard!!
- After that, re-use the strpos to find the next " (using the 'offset' parameter as you want to search from the previous position you got from the other strpos.
-Then, use the substr function with the first position you got and the substraction of the two position to get the length of the string you want to get.
It should work easily!
Good luck...
ti_nhatrang 10-04-2006, 05:34 PM Actually, I learn it well when I see the code itself... If you could please kindly help me....
jobinma 10-04-2006, 05:39 PM Go on http://php.net
The functions are explained very well and there are examples too. Doing it for you is the best way not to help you...
It's 3 lines of code.... come on!
ti_nhatrang 10-04-2006, 05:41 PM believe me, if I get it, I'll do it. You don't even need to tell me where it is in PHP.net or on google or anywhere else... This is my last resort, please help...
lutan 10-04-2006, 05:53 PM if there is only one link tag <a href...></a>, just search and extract it. what difficult?
The Prohacker 10-04-2006, 07:17 PM $site = "http://localhost/files/?=newfiles";
$open = fopen($site, "r");
$search = fread($open, 4096);
fclose($open);
$search = ereg("<td style=\"BORDER: none\"><p align=\"left\"><a href=\"(.*)\"><img src=", $search, $content);
print_r($content);
This code is untested but the syntax looks right and should give you a good place to start.
-Mat
ti_nhatrang 10-04-2006, 07:49 PM thank you that tried to help and those that saved me. Thanks all once again and I really appreciate it!
ti_nhatrang 10-04-2006, 11:53 PM I can't seem to get it to print the url for some odd reason, I even tried print $search... anybody got any solutions for this?
ti_nhatrang 10-05-2006, 04:09 AM After many attempts, this is as far as I got:
$dp = "http://localhost/files/?=newfiles";
if (!$dp)
{
echo("<P>Error: unable to load URL file into $dp. Process aborted.</P>");
exit();
}
$sp = file_get_contents($dp);
// highlight_string($sp);
$search = ereg("<td style=\"BORDER: none\"><p align=\"left\"><a href=\"(.*)\"><img src=", $sp, $content);
$surl = print_r($content);
print $surl;
}
No mater what I do trying to strip the string etc, it still gives me the below:
Array
(
[0] => <td style="BORDER: none"><p align="left"><a href="http://localhost/Files/%5BFrom%20drived%5D%9874.54314.95.zip"><img src=
[1] => http://localhost/Files/%5BFrom%20drived%5D%9874.54314.95.zip
)
how do I pull out [1] into an variable like $url = http://localhost/Files/%5BFrom%20drived%5D%9874.54314.95.zip ?
Please help, I'm almost there...
Thank you!
The Prohacker 10-05-2006, 08:44 AM echo $surl[1];
I learned PHP the same way you are by reading code and learning from it.
$surl is an array with two elements the original string and the URL you want.
-Mat
jobinma 10-05-2006, 09:38 AM You did it!!
Congratulations!!
ti_nhatrang 10-05-2006, 05:09 PM Thank you Matt, I know there are people out there that's like us. I stop asking for help here because everytime I do, I get these answers like sending me to php.net or mysql.com... simply useless... I also learn php that as well, along with design... I learn how to crop, cut, slice and design through looking at others, not reading a photoshop book, tutorials, or born gifted to have the skills. But thanks! I will try your method now...
ti_nhatrang 10-05-2006, 05:55 PM I can't get it to print out urls[1]... please help... have you try my code?
The Prohacker 10-05-2006, 07:45 PM Sorry, try echo $content[1];
|