By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Return Array

P: n/a
I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. Here is
what I have:

<?
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL, and return output
$output = curl_exec($ch);

// close curl resource, and free up system resources
curl_close($ch);

// Print output
$os = array("$output");

echo $os;

if (in_array("RFC 2606", $os)) {
echo "There is such thing";
}
?>

Any help is greatly appreciated.

Thanks
-Bryan
Sep 13 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Igoogler escribió:
I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. Here is
what I have:

<?
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL, and return output
$output = curl_exec($ch);

// close curl resource, and free up system resources
curl_close($ch);

// Print output
$os = array("$output");

echo $os;

if (in_array("RFC 2606", $os)) {
echo "There is such thing";
}
?>

Any help is greatly appreciated.

Thanks
-Bryan

what do you mean with returning an array from curl?
curl_exec returns a string containing the requested document.

This should help you (from php documentation http://fr2.php.net/curl_exec).

that way you can separate header and body, and then search what you want
in the body string.
public function exec()
{
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$result = array( 'header' ='',
'body' ='');

if ( $error != "" )
{
$result['curl_error'] = $error;
return $result;
}

$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
return $result;
}
Sep 13 '08 #2

P: n/a
On Sep 13, 12:02*pm, Romain Gilliotte <elo...@gmail.comwrote:
Igoogler escribió:
I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. *Here is
what I have:
<?
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
// Print output
$os = array("$output");
echo $os;
if (in_array("RFC 2606", $os)) {
* * echo "There is such thing";
* * }
?>
Any help is greatly appreciated.
Thanks
-Bryan

what do you mean with returning an array from curl?
curl_exec returns a string containing the requested document.

This should help you (from php documentationhttp://fr2.php.net/curl_exec)..

that way you can separate header and body, and then search what you want
in the body string.

* * *public function exec()
* * *{
* * * * *$response = curl_exec($this->ch);
* * * * *$error = curl_error($this->ch);
* * * * *$result = array( 'header' ='',
* * * * * * * * * * * * * 'body' ='');

* * * * *if ( $error != "" )
* * * * *{
* * * * * * *$result['curl_error'] = $error;
* * * * * * *return $result;
* * * * *}

* * * * *$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
* * * * *$result['header'] = substr($response, 0, $header_size);
* * * * *$result['body'] = substr( $response, $header_size );
* * * * *return $result;
* * *}
All I want to do is check and see if certain text is on the page. If
it is echo one thing, if it isn't echo another.
Sep 13 '08 #3

P: n/a
Igoogler escribió:
On Sep 13, 12:02 pm, Romain Gilliotte <elo...@gmail.comwrote:
>Igoogler escribió:
>>I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. Here is
what I have:
<?
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
// Print output
$os = array("$output");
echo $os;
if (in_array("RFC 2606", $os)) {
echo "There is such thing";
}
?>
Any help is greatly appreciated.
Thanks
-Bryan
what do you mean with returning an array from curl?
curl_exec returns a string containing the requested document.

This should help you (from php documentationhttp://fr2.php.net/curl_exec).

that way you can separate header and body, and then search what you want
in the body string.

public function exec()
{
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$result = array( 'header' ='',
'body' ='');

if ( $error != "" )
{
$result['curl_error'] = $error;
return $result;
}

$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] =
return $result;
}

All I want to do is check and see if certain text is on the page. If
it is echo one thing, if it isn't echo another.
well that's what I answered as well....
Is that better?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$header_length = curl_getinfo($ch,CURLINFO_HEADER_SIZE);

curl_close($ch);

$body = substr($response, $header_size);

if (ereg("What you are sesarching for", $body)) {
echo "I found it";
}
else {
echo "I didn't";
}

I'm sure there are faster functions that ereg to search for a string.
Sep 13 '08 #4

P: n/a
Romain Gilliotte wrote:
Igoogler escribió:
>On Sep 13, 12:02 pm, Romain Gilliotte <elo...@gmail.comwrote:
>>Igoogler escribió:

I am currently trying to return an array from curl and it doesn't seem
to be working. What I basically want it to is to search the remote
page for some text and then perform and If Then statement. Here is
what I have:
<?
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
// Print output
$os = array("$output");
echo $os;
if (in_array("RFC 2606", $os)) {
echo "There is such thing";
}
?>
Any help is greatly appreciated.
Thanks
-Bryan
what do you mean with returning an array from curl?
curl_exec returns a string containing the requested document.

This should help you (from php
documentationhttp://fr2.php.net/curl_exec).

that way you can separate header and body, and then search what you want
in the body string.

public function exec()
{
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$result = array( 'header' ='',
'body' ='');

if ( $error != "" )
{
$result['curl_error'] = $error;
return $result;
}

$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = return $result;
}

All I want to do is check and see if certain text is on the page. If
it is echo one thing, if it isn't echo another.

well that's what I answered as well....
Is that better?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$header_length = curl_getinfo($ch,CURLINFO_HEADER_SIZE);

curl_close($ch);

$body = substr($response, $header_size);

if (ereg("What you are sesarching for", $body)) {
echo "I found it";
}
else {
echo "I didn't";
}

I'm sure there are faster functions that ereg to search for a string.
1. The ereg-based functions should not be used. Rather, preg-based
functions are more desirable.

2. ereg/preg/whatever is way overkill for searching for a string within
a string. Rather, what you should be using is

if (strpos($body, 'RFC 2606') !== false) { ...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 13 '08 #5

P: n/a
Try the following code:

<?
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL, and return output
$output = curl_exec($ch);

// close curl resource, and free up system resources
curl_close($ch);

// Print output
if (!empty($output))
{
if ($stristr($output, "RFC 2606")
{
echo "There is such thing";
}
}
else
{
echo "Please check your usage of cURL.";
}

?>
Sep 14 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.