[PHP] XML API, libcurl, POST Help Needed

2007-01-07 Thread Richard Luckhurst
Hi List

I have been given a rather urgent problem to solve for one of our clients. I
have to be able to connect to a server that deals with a section of the travel
industry and send and receive XML data. The API is quite poorly written and I am
finding it hard to get sense out of the companies help desk. I would appreciate
the help of the list in getting me pointed in the right direction.

The API expects a custom header and then a request. I have built the header and
I think it is OK. The request is an XML request and this is where I believe I am
having problems. I am getting an error response from the server telling me I
have invalid XML.

I am really stumped with the XML part. I have no idea how to code this section
and it appears what I am doing is not correct. I have spent days searching the
net looking for clues and so far have not succeeded.

I would appreciate help and guidance. If anyone needs any more information
please do not hesitate to ask.

This is what I have so far (note I have hidden usernames and passwords)

200ALL';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PORT, $port);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_TIMEOUT, 40);
curl_setopt($curl, CURLOPT_VERBOSE, 1);

$response = curl_exec($curl);
if(curl_errno($curl))
{
print curl_error($curl);
}
else
{
curl_close($curl);
}

print "$response\n\n\n";

?>

I thank you in advance for any help.



Regards,
Richard Luckhurst
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



Re[2]: [PHP] XML API, libcurl, POST Help Needed

2007-01-07 Thread Richard Luckhurst
Hi Jochem,

Thanks very much for your help. I now have the application working. Just for
anyone elses interest here are a few comments.


>> $length = "Content-Length: 502";

JM> The way I see it your Content-Length is wrong - the
JM> length of your request in this instance would 380 bytes,
JM> based on the length of $xmlstr. but that's probably not right
JM> either.

JM> I imagine you need to set Content-Length dynamically,
JM> assuming curl doesn't do that for you ...

Yes curl does it for you I have discovered. So I removed this Content-Length and
found that it is now dynamically generated.

JM> as a side note: why bother setting all these vars then stricking
JM> them in an array - why not just stick the strings directly in the array?
JM> additionally if you don't need to use double quotes (for variable
JM> interpolation) single quotes are [marginally] faster [in theory] because
JM> no variable interpolation is attempted on them.

Because I was being a bit lazy and wanted to see more of what was going on. Of
course you are right and I have now cleaned up my code as you have suggested.

>> $a_encoding = "Accept-Encoding: gzip";

JM> not related to your current issue, but are your really accepting
JM> a gzip'ed reply? this might cause you headaches once you have the
JM> current problem solved.

Yeah this gzip is a real pain. The API specifies either a gzipped or a
compressed data transfer. Some of the returns from the server, in Germany, can
be quite large so I guess the developers wanted to save some bandwidth by
compressing the data. I have just discovered that if I leave the
Accept-Encoding: gzip out all together then the whole process works with the
data returned in plain uncompressed text :-)


>> curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));

JM> I am guessing that the urlencoded $xmlstr should be given a POST parameter 
name,
JM> what that name is I don't know but the previous line should look something 
like
JM> this (*I think*):

JM> curl_setopt($curl, CURLOPT_POSTFIELDS, array('xml' => urlencode($xmlstr)));

This was where I had suspected I was having trouble. What I did find was that
the whole thing now works just by removing the urlencode all together. It
appears that the Content-Length was the problem all along and once that was
fixed and the urlencode was removed everything was fine.

JM> you might consider point the curl request to a script you control,
JM> so that you can see exactly what the request is sending.

JM> e.g. $url = 'http://yourdomain.tld/your-curl-request-test.php';

JM> ... and have your-curl-request-test.php write all it's recieved headers, etc
JM> to a log file.

Probably a good idea for debugging.

Thanks for your help.



Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



[PHP] Parsing an XML return from a POST

2007-01-08 Thread Richard Luckhurst
Hi List

I am working owards completing a rather urgent project for one of our clients.
There is a requirement to send a request to a server and I now have that working
using cURL, thanks to help from this list. I now have the responses coming back
as an XML response. What I need to do is to parse the XML response and break it
up into either an array or variables so I can pass the returned responses back
to a calling process.

I have spent most of last night and today looking at XML parsing and now am
totally confused. Some testing I have done suggests that SimpleXML is not the
way to go however I am open to suggestions if it might be an answer. I would
appreciate any help or advice on how to parse this XML response and break it up
into either an array or individual variables.

I have included a sample response from the server below. A few points to be
aware of,

1) In the fares section there could be any number of fares however each fare
will have a fareID and then the fareBases child.
2) In the tarifs section there could be any number of tarifs however each tarif
will have a tarifId and then 1 or more fareXrefs.
3) In the vcrSummary section there could be 1 or more vcr entries
4) The response comes back as one long string and I have formatted this to make
it a little easier to read.




  


VLOX2
VLOX2
VLOX2




MLOW2
MLOW2
MLOW2


  
  


11429927




11429926


  
  
201.52
  
  
AA
PR
  


  
I would certainly appreciate any help I can get. Thanks in advance.

Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



[PHP] Parsing an XML return from a POST - resend with a little more information

2007-01-09 Thread Richard Luckhurst
Hi List

I am sending this to the list again with a bit more information in the hope I
can get some help.

There is a requirement to send a request to a server and I now have that working
using cURL, thanks to help from this list. I now have the responses coming back
as an XML response. What I need to do is to parse the XML response and break it
up into either an array or variables so I can pass the returned responses back
to a calling process.

I have spent most of last night and today looking at XML parsing and now am
totally confused. Some testing I have done suggests that SimpleXML is not the
way to go however I am open to suggestions if it might be an answer.

I have spent ages searching Google and looking at XML parser examples. Now I am
more confused than ever.

I would appreciate any help or advice on how to parse this XML response and 
break it up
into either an array or individual variables. It is important for this
application to not only get the data contained between beginning and end tags
but also the attributes as they contain important data returned from the server.
I am the first to admit that PHP XML Parsing has me lost.

One other question I do have is that all of the examples I have seen, using the
xml_parser, seem to be designed around a file being read into the parser. Is it
possible for the XML data to be contained in a variable and then used in the
parser?

I have included a sample response from the server below. A few points to be
aware of,

1) In the fares section there could be any number of fares however each fare
will have a fareID and then the fareBases child.
2) In the tarifs section there could be any number of tarifs however each tarif
will have a tarifId and then 1 or more fareXrefs.
3) In the vcrSummary section there could be 1 or more vcr entries
4) The response comes back as one long string and I have formatted this to make
it a little easier to read.




  


VLOX2
VLOX2
VLOX2




MLOW2
MLOW2
MLOW2


  
  


11429927




11429926


  
  
201.52
  
  
AA
PR
  


  
I would certainly appreciate any help I can get. Thanks in advance.



Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



Re[2]: [PHP] Parsing an XML return from a POST - resend with a little more information

2007-01-09 Thread Richard Luckhurst
Hi Roman,


RN> What makes you think simplexml is not for you? I don't say it is, but
RN> you need to tell us exactly what you need.
RN>

From what I can see, unless I am mistaken, SimpleXML can not deal with
attributes within a tag. It only seems to deal with data contained between a
start tag and an end tag. I have a lot of data contained within the start tags
that I must extract.


RN> http://php.net/manual/en/ref.simplexml.php has quite a few examples in
RN> the user-contributed notes. Have you seen the manual?
RN>

Yes of course I have seen the manual.


RN> Many of the examples at http://php.net/manual/en/ref.simplexml.php use a
RN> string variable as the source.

Yes I know they do but the examples for xml_parse() do not use a string.



Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



Re[2]: [PHP] Parsing an XML return from a POST - resend with a little more information

2007-01-09 Thread Richard Luckhurst
Hi Jochem,

Thanks for your reply. Here is a short sample of the XML I have to parse. I need
the data in the attributes as well as the data in the character fields.




  


VLOX2
VLOX2
VLOX2




MLOW2
MLOW2
MLOW2


  
  


11429927




11429926


  
  
201.52
  
  
AA
PR
  





JM> me, I'm pretty convinced simpleXML is what he wants.

JM> simpleXML was a dog to use in earlier versions of php5 because simpleXML 
objects
JM> were 'immune' to inspection by var_dump(), print_r(), etc [meaning you be 
told some
JM> property was an array and then get an error if you access said property as 
an array,
JM> stuff like that].

JM> those problems have been helped the way of the dodo so now simpleXML really 
does
JM> what it says on the tin.

JM> of course there is always the options of using regular expressions or simple
JM> string manipulation functions to extract the relevant data from the string 
of
JM> 'xml' - technically there is no need to go anywhere near a 'real' xml parser
JM> as such.

So far I have had no luck with simpleXML at all.

Regards

Richard Luckhurst

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



Re[2]: [PHP] Parsing an XML return from a POST - resend with a little more information

2007-01-10 Thread Richard Luckhurst
;@attributes"]=>
array(9) {
  ["tarifId"]=>
  string(8) "11429926"
  ["adtBuy"]=>
  string(6) "714.83"
  ["adtSell"]=>
  string(6) "714.83"
  ["chdBuy"]=>
  string(6) "714.83"
  ["chdSell"]=>
  string(6) "714.83"
  ["infBuy"]=>
  string(6) "714.83"
  ["infSell"]=>
  string(6) "714.83"
  ["topCar"]=>
  string(5) "false"
  ["topHotel"]=>
  string(5) "false"
}
["fareXRefs"]=>
object(SimpleXMLElement)#13 (1) {
  ["fareXRef"]=>
  string(8) "11429926"
}
  }
}
  }
  ["taxes"]=>
  object(SimpleXMLElement)#4 (2) {
["@attributes"]=>
array(1) {
  ["currency"]=>
  string(3) "USD"
}
["tax"]=>
string(6) "201.52"
  }
  ["vcrSummary"]=>
  object(SimpleXMLElement)#5 (1) {
["vcr"]=>
array(2) {
  [0]=>
  string(2) "AA"
  [1]=>
  string(2) "PR"
}
  }
}


So I can clearly see the data I want is there. However I have tried the
following

 foreach ($data->fares as $fares)
 {
print "{$fares->fares} \n";
 }

And that just produces a blank line. It is obvious to me that I am not on the
right track.

Regards

Richard Luckhurst

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



[PHP] XML Parsing simpleXML Arrays Question

2007-01-14 Thread Richard Luckhurst
Hi List

I have taken the advice of a number of people on the list and am back trying to
write my XML parser using SimpleXML. I am having a problem and I believe the
problem is my lack of understanding of arrays and simpleXML in spite of much
google searching and manual reading. I would appreciate some help.

The piece of XML I am parsing is as follows. I am working with a small section
to see if I can get my head around it.





  
AA
PR
  


If I use the following

$file = "test.xml";


  $data = simplexml_load_file($file);

  foreach ($data->vcrSummary as $vcrSummary)
  {
var_dump($vcrSummary); 
   }

Then I get

object(SimpleXMLElement)#5 (1) {
  ["vcr"]=>
  array(2) {
[0]=>
string(2) "AA"
[1]=>
string(2) "PR"
  }
}

Which is pretty much what I would expect as there are 2 vcr tags.

If I then use

$file = "test.xml";


$data = simplexml_load_file($file);

foreach($data as $vcrSummary)
{
$z = $vcrSummary->vcr;
print "$z \n";


}

I get 3 blank lines and then AA which is the first of the two vcr values. The
examples I am looking at suggest I should have gotten both of the vcr values.

Many of the examples I am looking at say to use echo instead of print, eg

echo $vcrSummary->vcr;

and that just gives me AA and not both values that I would expect.

Can anyone point me in the right direction here.

Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



[PHP] socket_write buffer problem

2007-01-21 Thread Richard Luckhurst
Hi List

I am working with an application that has to run as a socket listener. It
receives a string from another application on a certain socket and then does
some processing and then passes the result back to the client application via
the socket. Here is the listener code I am using

while(true)
{
$client = socket_accept($socket);

$arev_data = socket_read($client, 1024);

$yresponse = build_XML_request($arev_data);

socket_write($client, $yresponse);

socket_close($client);

}
socket_close($socket);

The application is working fine but I have just noticed that when the $yresponse
variable is larger than 1024 bytes the string returned to the client is
truncated. I just had a look at the php manual for socket_write and it
mentions that truncating the data at the buffer size can be a problem. The
manual does not offer any possible solutions though. I am stumped here as the
value for $yresponse will often be larger than 1024 bytes and its length is
quite variable.

Does anyone have any suggestions on how I can make sure the entire contents of
$yresponse are passed back to the client?

  


Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.

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



Re[2]: [PHP] socket_write buffer problem

2007-01-21 Thread Richard Luckhurst
Hi Jochem,


JM> I would start by reading the relevant page:

JM> http://php.net/socket_write

JM> after reading that your first attempt will probably be this
JM> (you may have complication is your using a multibyte charset):

As I had said in my earlier post I had already read the php manual section for
socket_write.

JM> socket_write($client, $yresponse, strlen($yresponse));

JM> if that doesn't work, you will be looking at capturing the return value
JM> of socket_write() in order to determine how many bytes were sent ...
JM> this information will allow to to use a loop to call socket_write as many 
times
JM> as is required to send all the data. hope that makes sense to you.

I tried the strlen($yresponse) length option in socket_write and it did not
matter if I set socket_write to anything larger than 1024. It appears that there
is a buffer with a size of 1024 and in my case the length option would only be
of use if the string I wanted to send was shorter than the size of the buffer.

Rather than capturing the return value of socket_write I broke my test string
into 2 chunks as the total was less than 2048 bytes.

What I tried was

 // grab first 1024 bytes
 $buffer = substr($yresponse,0,1024);
 // send first 1024 bytes
 socket_write($client, $buffer);
 // replace first 1024 bytes with ''
 $buffer = substr_replace($yresponse,'',0,1024);
 //send the remainder of the string
 socket_write ($client, $buffer);

What I found was that the first 1024 bytes was sent but I still never saw the
second 1024 bytes. It seem the second socket_write is not happening.

Am I on the right track here?

>> 
>>   
>> 
>> 
>> Regards,
>> Richard Luckhurst  
>> Product Development
>> Exodus Systems - Sydney, Australia.
>> 

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



Re[2]: [PHP] socket_write buffer problem

2007-01-21 Thread Richard Luckhurst
Hi Jochem,


JM> I would start by reading the relevant page:

JM> http://php.net/socket_write

JM> after reading that your first attempt will probably be this
JM> (you may have complication is your using a multibyte charset):

As I had said in my earlier post I had already read the php manual section for
socket_write.

JM> socket_write($client, $yresponse, strlen($yresponse));

JM> if that doesn't work, you will be looking at capturing the return value
JM> of socket_write() in order to determine how many bytes were sent ...
JM> this information will allow to to use a loop to call socket_write as many 
times
JM> as is required to send all the data. hope that makes sense to you.

I tried the strlen($yresponse) length option in socket_write and it did not
matter if I set socket_write to anything larger than 1024. It appears that there
is a buffer with a size of 1024 and in my case the length option would only be
of use if the string I wanted to send was shorter than the size of the buffer.

Rather than capturing the return value of socket_write I broke my test string
into 2 chunks as the total was less than 2048 bytes.

What I tried was

 // grab first 1024 bytes
 $buffer = substr($yresponse,0,1024);
 // send first 1024 bytes
 socket_write($client, $buffer);
 // replace first 1024 bytes with ''
 $buffer = substr_replace($yresponse,'',0,1024);
 //send the remainder of the string
 socket_write ($client, $buffer);

What I found was that the first 1024 bytes was sent but I still never saw the
second 1024 bytes. It seem the second socket_write is not happening.

Am I on the right track here?

>> 
>>   
>> 
>> 
>> Regards,
>> Richard Luckhurst  
>> Product Development
>> Exodus Systems - Sydney, Australia.
>> 

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



[PHP] Re: socket_write buffer problem

2007-01-21 Thread Richard Luckhurst
Hi List

I have been banging my head against a wall all day trying to work this problem
out. To recap my earlier post, I have a simple socket listener that handles the
incoming string fine with socket_read and then it fires off the application as
it should. When it returns the data to the socket only the first 1024 bytes get
sent.

I have done some testing and for the life of me I can not find a way to loop
through the buffer. Everything I try still results in only the first 1024 bytes.

Here is the code I have been trying

while(true)
{
$client = socket_accept($socket);

$arev_data = socket_read($client, 1024);

$yresponse = build_XML_request($arev_data);

if (strlen ($yresponse) < 1024)
{
socket_write($client, $yresponse);
}
else
{   
while (strlen($yresponse) > 0)
{
if (strlen ($yresponse) > 1024)
{   
$out = substr($yresponse, 0, 1024);
socket_write($client, $out, 
strlen($out));
$yresponse = 
substr_replace($yresponse,'',0,1024);
}
else
{
socket_write($client, $yresponse);
print "$yresponse ";
$yresponse = 
substr_replace($yresponse,'',0,strlen($yresponse));
}

}

} 

socket_close($client);
}

Just for testing I cave an if statement that takes care of the case where there
is a data string of less than 1024 bytes. The problem starts when I get into the
else case where the$response is larger than 1024 bytes. The if statement seems
OK and the first time through when the test data is 1521 bytes the first 1024
bytes gets returned by the socket_write. I then get rid of the first 1024 bytes
of the string and the if statement falls through to the else as the string is
now only 497 bytes left in the $ypsilon string. I see nothing returned to the
client by the socket_write here however the print "$yresponse \n"; prints the
data. I can not work out why the socket_write is not writing the data to the
socket at this point.

Does anyone have any clues?

Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.

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



[PHP] Regular Expression Problem

2007-01-24 Thread Richard Luckhurst
Hi List

I must be dumb as I have been battling my way through regular expression
examples for a while and I can not work out why the following does not work
properly. I am the first to admit that regular expressions confuse me greatly.

The string is a piece of XML as follows and I have put that string into a
variable called $xml_string



 
 
   
   
 
 
 
 
   
   
 
 



What I am trying to do is extract the first  chunk.

I am using the following, based on the example at
http://php.net/manual/en/function.preg-match.php example 3

preg_match('##', $xml_string,$matches);
$tempstr = $matches[0];

What I actually get in $tempstr is everything from the first 

I would have expected preg_match to have matched from the first .

I suspect I do not have the regular expression correct. I would great appreciate
any help on sorting out the regular expression so that it only returns the first
chunk of the string.



Regards,
Richard Luckhurst

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



Re[2]: [PHP] Regular Expression Problem

2007-01-24 Thread Richard Luckhurst
Hi Roman,

RN> Are you doing this to learn regular expressions or are you actually
RN> trying to do work? Because you're going the wrong way.
RN> It's XML, why do you treat it as text?

I am well aware it is XML and I could use an XML parser or simpleXML. I am
trying to learn regular expressions as I have a fair bit of work coming up that
will require the use pattern matching within strings. It just so happens that
some of the data looks like XML, hence the reason I am using a piece of XML for
this learning process.


Regards

Richard

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



Re[2]: [PHP] Regular Expression Problem

2007-01-24 Thread Richard Luckhurst
Hi Jochem,

JM> 
JM> you be needing an ungreedy modifier on yer regex.
JM> 

JM> see here:
JM> http://php.net/manual/en/reference.pcre.pattern.modifiers.php

RL Thanks very much. That solved my problem and I my now getting exactly what I
RL want. I had seen the reference to greedy and ungreedy but had not understood 
the
RL concept.

RL Regards

RL Richard

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



[PHP] PHP equivalent to Perl $0

2007-01-31 Thread Richard Luckhurst
Hi 

In Perl there is the predefined $0 which contains the name of the file
containing the Perl script being executed. Is there an equivalent in PHP?

I am working on converting a Listener script from Perl to PHP and at one point
when the script forks it has a line

$0 = "Listener is accepting connections on Port $port";

When this Perl script is running and I do a ps I see a process ID with the
program being

Listener is accepting connections on Port $port
  
instead of the actual name of the Perl script.

Is such a thing possible in PHP? If so how? I have been Google searching for a
while and can not see one way or the other if it is possible.



Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.

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



Re[2]: [PHP] PHP equivalent to Perl $0

2007-01-31 Thread Richard Luckhurst
Hi Richard,


RL> And, frankly, why would you want to do that?  It only sows confusion
RL> in ps output. :-)

I happen to agree with you. Why would you want to do it. The reason it is being
done in this application is to keep a specification for he application happy.

When the php program is executing and you do a ps you see

/usr/local/bin/php -q listener.php

which is perfectly fine by me :-)

What happens with the Perl application beacuse of stuffing the string back into
the $0 is that you see

Listener is accepting connections on Port 15556

It seems to me that whoever wrote the specification had this thing about ps
showing a nice string instead of the program name actually running. Of course I
know that this is what ps is supposed to do and Perl allows you to tell nice
lies to ps :-)



Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

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



[PHP] Help with preg_replace

2007-11-07 Thread Richard Luckhurst
Hi 

I am in the process of porting a Perl application to PHP and I have hit a snag
with trying to substitute test within a file. I have looked at the PHP manual
and believe I should be using preg_replace but I have tried the examples and am
not getting the result I would expect. I would appreciate any help in getting
this to work.

In Perl I have the following

$html = `cat htmlfile`;
$html  =~ s/%ResID/$bookid/g;

which replaces each instance of %ResID with the contents of the variable $bookid

In PHP I have tried

$html = `cat htmlfile`;
$html = preg_replace('%ResID',$bookid,$html);

When I run this I find $html is empty rather than containing the file with the
%ResID replaced with the contents of $bookid.

I would appreciate any help with my understanding of preg_replace.



Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com 
=
Exodus Systems - Smarter Systems, Better Business
=

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



[PHP] preg_replace Question

2008-04-03 Thread Richard Luckhurst
Hi List

I am trying to perform a number of replacements of place holders in an html page
I am working on using preg_replace. I am stuck with a pronlem I can not work out
and would appreciate some help.

The code I have is as follows

$html = preg_replace('/%Amount/',$amount,$html);

$html is the source of a html page
$amount is set earlier to a value read from a file

When I view the html page the value of %Amount is not what I would expect.

e.g $amount = $524.00 however only 4.00 is displayed in the %Amount field on the
html page. I tried dropping the .00 from $amount to see if this might be a
length issue and then %Amount was just 4

Am I doing something obviously wrong here? I have checked the php manual and I
appear to be using preg_replace correctly.


Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com 
=
Exodus Systems - Smarter Systems, Better Business
=


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



[PHP] Sending data to PS

2008-04-30 Thread Richard Luckhurst
Hi List

In Perl it is possible to use the syntax

 $0 = "$LISTENER: accepting connections on $SERVER_PORT";

to set a meaningful test string for ps.

Is such a thing, or anything similar, available for PHP?
  


Regards,
Richard Luckhurst  



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



[PHP] equivalent to perl shift function

2008-05-01 Thread Richard Luckhurst
Hi All

I am in the process of porting a perl script and I am trying to fin out if there
is a php equivalent to the perl shift function? I have been looking at the php
manual and google searching so far with no luck.

  


Regards,
Richard Luckhurst  



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



Re[2]: [PHP] equivalent to perl shift function

2008-05-01 Thread Richard Luckhurst
Hi Chris,

In perl ther is the concept of @_  which is the list of incoming parameter to a
subroutine. It is possible to have something like

my $sock = shift;

As I understand this the first parameter of the @_ list would be shifted.

I see for array_shift there must be an argument, the array name to shift, while
in perl if the array name is omitted the @_ function list is used. Is ther a php
equivalent to the @_ list or how might I use array_shift to achieve the same
result as in perl?

C> Richard Luckhurst wrote:
>> Hi All
>> 
>> I am in the process of porting a perl script and I am trying to fin out if 
>> there
>> is a php equivalent to the perl shift function? I have been looking at the 
>> php
>> manual and google searching so far with no luck.

C> http://www.php.net/manual/en/function.array-shift.php




Regards,
Richard Luckhurst



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



[PHP] Extended Ascii Characters

2006-06-01 Thread Richard Luckhurst
Hi All

I am in the process of cleaning up an application that was left half finished. I
am fairly new to PHP so I am seeking the wisdom of the community to help with a
little problem.

In many cases I need to build command strings to be sent to a backend system.
The strings have to contain a couple of non ascii characters.

I have no problem with the following in a script

$RM="\xFF";

Then using the variable works fine within that chunk of php code.

What I would like to do is place all of the extended ascii characters in one of
the inc files and just use these in various scripts throughout the application.

When I try what I get is a test representation rather than the actual ascii
code. Ie I get \xFF instead of the ascii character ÿ

Is there any way to actually do this in php?
  


Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com 
=
Exodus Systems - Smarter Systems, Better Business
=

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



Re[2]: [PHP] Extended Ascii Characters

2006-06-02 Thread Richard Luckhurst
Hi Tedd,

I had a hunt in the archives and couldn't find anything. Do you have any clue
about when it was?

Richard

t> At 9:46 AM +1000 6/2/06, Richard Luckhurst wrote:
>>Hi All
>>
>>I am in the process of cleaning up an application that was left half 
>>finished. I
>>am fairly new to PHP so I am seeking the wisdom of the community to help with 
>>a
>>little problem.
>>
>>In many cases I need to build command strings to be sent to a backend system.
>>The strings have to contain a couple of non ascii characters.
>>
>>I have no problem with the following in a script
>>
>>$RM="\xFF";
>>
>>Then using the variable works fine within that chunk of php code.
>>
>>What I would like to do is place all of the extended ascii characters in one 
>>of
>>the inc files and just use these in various scripts throughout the 
>>application.
>>
>>When I try what I get is a test representation rather than the actual ascii
>>code. Ie I get \xFF instead of the ascii character ÿ
>>
>>Is there any way to actually do this in php?
>> 
>>
>>
>>Regards,
>>Richard Luckhurst 
>>Product Development


t> Yes, I think there is  -- we discussed this a few months ago on this list 
and someone wrote a routine to do basically want you want, or so I think -- so 
check the archives.

t> tedd

t> -- 
t> 

t> http://sperling.com  http://ancientstones.com  http://earthstones.com

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