473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CURL functions to get source code of a url

130 100+
hello all

im trying to get the source code of a website,
i mange to do this with curl
snipt:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ch = curl_init("http://somesite.com/with/page/url.html");
  3. $fp = fopen("/tmp/site.txt", "w+");
  4. curl_setopt($ch, CURLOPT_FILE, $fp);
  5. curl_setopt($ch, CURLOPT_HEADER, 0);
  6. curl_exec($ch);
  7. curl_close($ch);
  8. fclose($fp);
  9. $hand = fopen("/tmp/site.txt","r");
  10. $lines ="";
  11. while(!feof($hand)){
  12.     $lines .= fgets($hand);
  13. }
  14. $code = trim(substr($lines,strpos($lines,"<a"),strpos($lines,"</a>")));// i want <a></a> tag
  15. $herf =substr($code,10,100);// the numbers are bogus 
  16. //at the end i am returring the tag or inserting it to a db 
  17. fclose($hand);
  18. ?>
  19.  
this code is working fine but BUT
i want to know is there a better way... i dont want my server to open and close file every time one of the guys will run the script
is there a way to do it in the server memory to get a response faster?

thanks head
Apr 14 '08 #1
2 4756
ronverdonk
4,258 Expert 4TB
When you mean that different user sessions have to write in SHARED storage, the answer is: not in PHP.

Ronald
Apr 17 '08 #2
Amzul
130 100+
When you mean that different user sessions have to write in SHARED storage, the answer is: not in PHP.

Ronald
thats not what i ment but can you explian with what it can b possible.

in my case i did this: instead of fopen i left it as a string
snipt:

Expand|Select|Wrap|Line Numbers
  1. $ch = curl_init("www.somepageurl.com");         
  2. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3. curl_setopt($ch, CURLOPT_HEADER, 0);            
  4. $file = curl_exec($ch);
  5. curl_close($ch);
$file contain the string that i need (no head) and i can work with it
Apr 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: GluedToTheScreen | last post by:
I have a small PHP ecommerce site set up using Authorize.net's SIM (simple) interface. Working fine, but... I'd like to implement their AIM interface (so visitor's will never see the gateway's...
8
by: mrbog | last post by:
1. In order to make an http (or https) request with PHP, I need to recompile php with cURL. 2. In order to install CURL I have to upgrade my openssl rpm, even though I'm runing a version of...
9
by: Conrad F | last post by:
Hi, If any Microsoft people are listening.... Are there any plans for the new web language called "Curl" to be supported in .NET (ASP.NET)? I ask as Curl represents the first step to true OO...
6
by: Wescotte | last post by:
I'm writing a tiny php app that will log into our bank of america account and retrieve a file containing a list of checks that cleared the previous day. The problem I'm running into is when I...
7
by: lawrence k | last post by:
I'm reading over this page: http://www.php.net/manual/en/ref.curl.php What I'm missing is why? What problem does curl solve? What does it make easier? When would I use its functions, instead...
6
by: Velhari | last post by:
Hello sir, Using Curl Function in PhP, i got the source of a Web page . In that I did not want the entire content, like some contents are all not needed so i have to eliminate those contents from...
7
by: h.stroph | last post by:
Greetings, I apologize for my lack of literacy with php, but am wondering if someone will tell me how to use the curl php functions to navigate to the page that results from entering the login...
1
by: jeddiki | last post by:
Hi, I am modifying a ipn script for my use and want to fully understand what it is doing. It seems to me that it is trying to do a cUrl and if that fails it uses a fsockopen function. Here are...
3
by: jeddiki | last post by:
I am using curl to down load a zip file and I am then trying to unzip it, but I don't think that I am using the functions properly because I get warnings This is my code: <?php if...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.