Jump to content

syntax error, unexpected '$curl' (T_VARIABLE)


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
https://forums.phpfreaks.com/topic/288301-syntax-error-unexpected-curl-t_variable/
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;

?>

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.

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;

?>

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().

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.