Jump to content

syntax error, unexpected '$curl' (T_VARIABLE)


Go to solution Solved by requinix,

Recommended Posts

<?php
    $url = "http://www.something.com";
	
    $curl = curl_init();
	curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$curlresult = curl_exec ($curl);
	curl_close($curl);
	
	preg_match_all("/ something=something/", $curlresult, $theurls);
	
	$string = serialize($theurls);
	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER2['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $string);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$curlresult2 = curl_exec ($curl);
    curl_close ($curl);
    
print $curlresult2;

?>

so im realy new to php and its probably a silly mistake .-.

this is the answer i got from wamp syntax error, unexpected '$curl' (T_VARIABLE)

anyway , can some one help me?

Link to comment
Share on other sites

There's nothing wrong with what you posted.

 

What line had the problem? What editor are you using?

notepad++ 

remove the space in this line:

 

before

$curlresult2 = curl_exec ($curl);

 

after

$curlresult2 = curl_exec($curl);

he hasnt there before hehehe but same error 

<?php
    $url = "http://www.site.com";
	
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlresult = curl_exec ($curl);
    curl_close($curl);
	
    preg_match_all("/ imsmartasamonkey=\"(.*)\">(.*)<\/a><\/p>/", $curlresult, $theurls);
	
    $string = serialize($theurls);
	
    $curl = curl_init(); /*ERROR IS IN THIS LINE*/
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER2['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $string);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlresult2 = curl_exec ($curl);
    curl_close ($curl);
    
    print $curlresult2;

?>
Link to comment
Share on other sites

You might have some invisible badness near there. Shift+space sometimes creates non-breaking spaces, which PHP does not treat the same as regular spaces.

 

Do you have the option to "show all characters" enabled? Turn it on and see if there's something unusual hiding around that line.

Link to comment
Share on other sites

the problem was solved by redoing the spaces and replacing the $SERVER2 with $SERVER , but now it shows nothing as result...the first Curl is getting multiple urls, i think i might need a foreach or something no ? i will try to clean the first Curl result

<?php
    $url = "http://www.site.com";
	
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlresult = curl_exec ($curl);
    curl_close($curl);
	
    preg_match_all("/ href=\"(.*)\">(.*)<\/a><\/p>/", $curlresult, $theurls);
	
    $string = serialize($theurls);
	
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($curl, CURLOPT_URL, $string);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlresult2 = curl_exec ($curl);
    curl_close ($curl);
    
    print $curlresult2;

?>
Edited by bores_escalovsk
Link to comment
Share on other sites

I have absolutely no idea why you're trying to use serialize(). What do you expect this function to do? If you check the manual, you'll see that it creates a technical string representation of a value to be stored for later deserialization. That's not exactly helpful in your case.

 

I also don't get why you throw away the first cURL instance and create a new one. What's wrong with the first one?

 

Regarding multiple URLs, you want curl_multi_init().

Link to comment
Share on other sites

I have absolutely no idea why you're trying to use serialize(). What do you expect this function to do? If you check the manual, you'll see that it creates a technical string representation of a value to be stored for later deserialization. That's not exactly helpful in your case.

 

I also don't get why you throw away the first cURL instance and create a new one. What's wrong with the first one?

 

Regarding multiple URLs, you want curl_multi_init().

thats my semi-monkey IQ hehe , thanks u realy helped . what i was trying to do is check a page of search(not google) and enter on each link of the search.

kinda like a spider but with a filter.

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.