• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

How to create a function from this code?

Hi Folks,

I have this fragment of code, which will check whether a certain topic is either closed or opened. Now I would want to turn this into a function with one parameter being the url.

Can anyone help me out?

Kind regards,

Dweep

Ps eventually I want to use this function to check multiple urls.
$ch = curl_init();
$url = "http://www.blahdieblah.com/topics/43";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
 
 
if (preg_match("/Comments are closed./", $contents)) {
    echo "This topic is closed.";
} else {
    echo "This topic is open.";
}

Open in new window

0
PeterdeB
Asked:
PeterdeB
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you mean:
function do_work($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
 
 
if (preg_match("/Comments are closed./", $contents)) {
    echo "This topic is closed.";
} else {
    echo "This topic is open.";
}
} 

and call it: 
do_work("http://www.blahdieblah.com/topics/43");

Open in new window

0
 
PeterdeBAuthor Commented:
Yes perfect thank you!!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now