php-general Digest 11 Sep 2012 04:41:17 -0000 Issue 7958

2012-09-10 Thread php-general-digest-help

php-general Digest 11 Sep 2012 04:41:17 - Issue 7958

Topics (messages 319027 through 319031):

Re: PHP CURL JSON POST Firebug
319027 by: ioannes.btinternet.com

Re: The end of mysql
319028 by: Larry Garfield
319029 by: Larry Garfield

How can I send custom message structures in SoapFault
319030 by: Néstor Boscán

another Array question
319031 by: admin

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---



On 04/09/2012 19:14, ioan...@btinternet.com wrote:



On 04/09/2012 18:41, Matijn Woudt wrote:

On Tue, Sep 4, 2012 at 7:35 PM, ioan...@btinternet.com
ioan...@btinternet.com wrote:

I am hoping someone can spot what is missing here.  I am getting null
result
from curl-ing a page with json post variables.

I try this url in my Firefox browser -

http://www.targetsite.com/search.php#somevar.someothervar

(#somevar.someothervar are irrelevant, I think, as I get the curl
variables
from Firebug below.)

In Firebug, this shows:

POST http://www.targetsite.com/ajax/search.xml

In Firebug, below this link are tabs for: Headers, Post, Response,
XML and
Cookies.  Post tab shows like:

JSON
VAR1   1
VAR2   2012-09-12
VAR3   null
CACHED []
OPTIONSnull

To prove there is output, the Firebug Response tab shows:

?xml version=1.0 encoding=utf-8?
JSON various JSON encoded stuff /JSON

The above is what I am trying to curl.

My php code:

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_POST, 1);

   //target page from Firebug above:
   curl_setopt($ch, CURLOPT_URL,
http://www.targetsite.com/ajax/search.xml;);

   //I was not sure how to represent CACHED [], so set it to null

try CACHED=array()

   $data = array(
 VAR1 = 1,
 VAR2 = 2012-09-12,
 VAR3 = null,
 CACHED=null,
 OPTIONS=null,
   );
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

   //make the request
   $result = curl_exec($ch);

   //this returns null

Any ideas where to go with this?  Maybe I need to include the
Cookies? I use
the above php and curl functions normally so it's all installed on the
server.

John


It might be that the site is using sessions/cookies. Have a look at
the header data with firebug.
Not sure if that's the problem, to find out what's really going on, call
echo curl_error($ch);
after curl_exec to find out what went wrong exactly.
If you still don't know how to proceed, paste the result of the
curl_error call in your reply.

- Matijn


I added the cookies to the post array.  I changed php array to
CACHED=array() for the JSON CACHED:[], and corrected php's null to
NULL.  It is not returning any error.  The browser was showing 'resource
not present' before I added the cookies to the post array, now it just
returns null $result.  Looks like I am transcribing something incorrectly.

John



I eventually sorted this out.  Solution involved:

POST params needed to be json_encoded
$params=json_encode(array(
name = value
));

Thanks to 
http://www.lornajane.net/posts/2011/posting-json-data-with-php-curl


curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

Also, included headers as array and set application type as json:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($post))
);

Set encoding to auto-detect:
curl_setopt( $ch, CURLOPT_ENCODING, );


John
---End Message---
---BeginMessage---
Then get a new host.  A host that disables PDO these days is a host that 
deserves to go bankrupt. ext/mysql has been dead for years now.


--Larry Garfield

On 09/08/2012 08:54 AM, Jim Giner wrote:

Nope. No PDO as yet either

jg


On Sep 7, 2012, at 11:22 PM, Adam Richardson simples...@gmail.com wrote:


On Fri, Sep 7, 2012 at 9:58 PM, Jim Giner jim.gi...@albanyhandball.com wrote:

So with the announced end of the mysql functions (and switching to a
different extension), one would think that my isp/hoster would be a bit more
interested in my dilemma.  I tried today to create my first mysqli-based
test script and found that I didn't have that extension.  A series of emails
with my tech support told me that the shared server farm does not get
mysqli - only their business servers.  Since I dont' have a need for and
want to pay more for a 'business server', I'm told I'm s... outta luck.

What about PDO? Is that available?

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




---End Message---
---BeginMessage---
And I didn't see the 

[PHP] another Array question

2012-09-10 Thread admin
Hello everyone,

I have a very long array. I want to pull all the data from the array
from a certain position to a certain position.
$myarray = array('0'='me', '1'='you','2'='her','3'='him','4'='them',
'5'='us');
Yes I know the array above it small it's an example, mine has over 150
positions.

$foundyou = array_search('you', $myarray);
$foundthem = array_search('them', $myarray);

Now I want to take all the array positions from $foundyou to $foundthem and
put their values into a variable;
For the life of me I can't remember how I did it.

I DO NOT want to foreach over the array positions that would be
counterproductive.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] another Array question

2012-09-10 Thread Jim Lucas

On 9/10/2012 9:41 PM, admin wrote:

Hello everyone,

I have a very long array. I want to pull all the data from the array
from a certain position to a certain position.
$myarray = array('0'='me', '1'='you','2'='her','3'='him','4'='them',
'5'='us');
Yes I know the array above it small it's an example, mine has over 150
positions.

$foundyou = array_search('you', $myarray);
$foundthem = array_search('them', $myarray);

Now I want to take all the array positions from $foundyou to $foundthem and
put their values into a variable;
For the life of me I can't remember how I did it.

I DO NOT want to foreach over the array positions that would be
counterproductive.



Well, depends on exactly what you mean by and put their values into a 
variable.  Do you mean concatenate all the values into one single 
flat variable.  Or do you mean to make a subset array of the values 
between your two points you found?



First, check out array_slice.
Second, look at join


?php

$myarray = array(
  '0'='me',
  '1'='you',
  '2'='her',
  '3'='him',
  '4'='them',
  '5'='us',
);

$s_pos = array_search('you', $myarray);
$f_pos = array_search('them', $myarray);

# Calculate the length, it is needed by array_slice()
$length = ($f_pos - $s_pos);

$subset_array = array_slice($myarray, $s_pos, $length);

print_r($subset_array);

$all_values = join(', ', $subset_array);

echo $all_values;

?

Obviously, you need to add in some error checking.  But that should get 
you started.


--
Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] another Array question

2012-09-10 Thread admin
Length was my problem the whole time.
Thank you very much.

Resolved 


-Original Message-
From: Jim Lucas [mailto:li...@cmsws.com] 
Sent: Tuesday, September 11, 2012 1:02 AM
To: admin
Cc: php-general@lists.php.net
Subject: Re: [PHP] another Array question

On 9/10/2012 9:41 PM, admin wrote:
 Hello everyone,

   I have a very long array. I want to pull all the data from the array

 from a certain position to a certain position.
 $myarray = array('0'='me', 
 '1'='you','2'='her','3'='him','4'='them',
 '5'='us');
 Yes I know the array above it small it's an example, mine has over 150 
 positions.

 $foundyou = array_search('you', $myarray); $foundthem = 
 array_search('them', $myarray);

 Now I want to take all the array positions from $foundyou to 
 $foundthem and put their values into a variable; For the life of me I 
 can't remember how I did it.

 I DO NOT want to foreach over the array positions that would be 
 counterproductive.


Well, depends on exactly what you mean by and put their values into a
variable.  Do you mean concatenate all the values into one single flat
variable.  Or do you mean to make a subset array of the values between your
two points you found?


First, check out array_slice.
Second, look at join


?php

$myarray = array(
   '0'='me',
   '1'='you',
   '2'='her',
   '3'='him',
   '4'='them',
   '5'='us',
);

$s_pos = array_search('you', $myarray);
$f_pos = array_search('them', $myarray);

# Calculate the length, it is needed by array_slice() $length = ($f_pos -
$s_pos);

$subset_array = array_slice($myarray, $s_pos, $length);

print_r($subset_array);

$all_values = join(', ', $subset_array);

echo $all_values;

?

Obviously, you need to add in some error checking.  But that should get you
started.

--
Jim


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php