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

Implode Help

P: n/a
Hello.

Quick background as I dont wish to hog anyones time. I am a customer of a
PHP/SQL programmer. A website that I had the programmer build for me is
working great, with one exception.

I have limited programming experience, most of it Pascal/C++ and I haven't
programmed for many years now even then it was mediocre programming of small
this and thats.

Here is the code:

-----------------------------------------------------------------------

function check_deliver_price($product_id, $product_quantity, $price_level,
$delivery_city_address, $delivery_state_address, $delivery_zip,
$values_price_inc)

{

global $db_prefix, $ups_dropOffChoice, $ups_container, $ups_billToUPS,
$ups_currency, $ups_document, $ups_22_destCountry, $ups_origCity,
$ups_15_origPostal, $ups_14_origCountry, $ups_13_product, $ups_10_action;

$result = 0;

@$result = mysql_query("select * from ".$db_prefix."_products WHERE
id='$product_id'");

@$myrow = mysql_fetch_array($result);

$value = $myrow['price_'.$price_level.'_level'] + $values_price_inc;

if ($value < 100) {$value = 100;}

$html = implode ('', file
('http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR
esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1
3_product.'&14_origCountry='.$ups_14_origCountry.' &origCity='.$ups_origCity.
'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.$ups_22_destCountry.
'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr
ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi
ce='.$ups_dropOffChoice.'&20_destCity='.$delivery_ city_address.'&19_destPost
al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l
ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[
'size_z']));

if (strstr($html, 'UPS United States'))

{

if (strstr($html, 'Provide Package Information'))

{

$result = 0;

}

elseif (strstr($html, 'Provide Shipment Information'))

{

$result = -1;

}

elseif (strstr($html, 'Detailed Results'))

{

eregi('Shipment Total:</span><img alt="" height="1" src="/img/1.gif"
width="12">(.+)<img alt="" height="1" src="/img/1.gif" width="6"><span
class="bold">USD</span></div></td>', $html, $temp);

$result = $temp[1];

}

else

{

order_step_1('', '', '', 'delivery_address_incorrect');

break;

}

}

if ($result < 0) {order_step_1('', '', '', 'delivery_address_incorrect');}

if ($myrow['price_'.$price_level.'_shipping'] == 1) {$result = 0;}

$result = $result * $product_quantity;

return $result;

}
-----------------------------------------------------------------------

Basically, from what I can gather, its looking within the webpage result
from UPS to see if something exists, in essence to give the
"check_deliver_price" function a result.

The use of "implode" in the above code (as in any PHP coding I would
imagine) is a concatenation function from what I can tell by my research.

However, it seems that the implode function call as used above is stripping
the space in between a customers City address (ie. Santa Fe, Los Angelos,
etc.) creating a situation where "Santa Fe" would be just "Santa" by the
time it is concatenated. Therefore, only "Santa" gets passed onto UPS by
use of the URL, which of course UPS returns an error.

Only customers with a space in the city name have this issue. Now, my
programmer while capable of resolving this issue, is absent and since she is
not even in the US, I cannot contact her.

I am asking the NG for any help in modifying the above code or any
suggestions as to what I can do. I dont mind keeping backups of her coding,
then modifying the original.. besides, I dont imagine I could make matters
much worse, since the "check_deliver_price" function is called both for
address verfication upon customer sign up, but, to find out the delivery
charges of the products that they purchase.

The key portion of the code (I think) would be:

$html = implode ('', file
('http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR
esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1
3_product.'&14_origCountry='.$ups_14_origCountry.' &origCity='.$ups_origCity.
'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.$ups_22_destCountry.
'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr
ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi
ce='.$ups_dropOffChoice.'&20_destCity='.$delivery_ city_address.'&19_destPost
al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l
ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[
'size_z']));
What I seek is an overall resolution to the code sniplet, though, I think if
I can find out from anyone here on how to fill in any spaces that may exist
in the $delivery_city_address variable with a %20, that would pretty much
resolve my issue?

Any guideance would be greatly appreciated, albeit, a modified code
resolving my issue would make it much easier and would be the most
appreciated assistance for this wannabe PHP programmer. :)

Jeff
Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
I noticed that Message-ID: <4r2jc.13825$2e6.5228@lakeread01> from Jeff
contained the following:
What I seek is an overall resolution to the code sniplet, though, I think if
I can find out from anyone here on how to fill in any spaces that may exist
in the $delivery_city_address variable with a %20, that would pretty much
resolve my issue?


The implode isn't doing it.

http://uk.php.net/manual/en/function.urlencode.php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

P: n/a
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:u6********************************@4ax.com...
I noticed that Message-ID: <4r2jc.13825$2e6.5228@lakeread01> from Jeff
contained the following:
What I seek is an overall resolution to the code sniplet, though, I think ifI can find out from anyone here on how to fill in any spaces that may existin the $delivery_city_address variable with a %20, that would pretty much
resolve my issue?


The implode isn't doing it.

http://uk.php.net/manual/en/function.urlencode.php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


Geoff,

Thank you very much for your assistance. I am reading and trying to gather
what I can using the link provided. While I am interested in learning PHP,
Im affraid that I might not figure things out until some time has passed.

If you or anyone else wouldn't mind rearranging/modifying the supplied code
so that it will work in the case where the city (or any other variable for
that matter I suppose) has a space in it, I would be very much in your debt.

I'll be watching intently to see if someone who doesnt mind doing this for
me, makes the changes.

I try to contribute where I can, unfortunately this is just one of those
NG's I cannot really contribute anything, but rather this is one that Im
visiting strictly as the collector vice contributor. :(

Jeff
Jul 17 '05 #3

P: n/a
I noticed that Message-ID: <s07jc.13972$2e6.2485@lakeread01> from Jeff
contained the following:
Geoff,

Thank you very much for your assistance. I am reading and trying to gather
what I can using the link provided. While I am interested in learning PHP,
Im affraid that I might not figure things out until some time has passed.


Sorry, from your response I guessed you were more savvy.

Try this: (you will probably have to get rid of the line wraps to make
it work)

$url='http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR
esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1
3_product.'&14_origCountry='.$ups_14_origCountry.' &origCity='.$ups_origCity.
'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.$ups_22_destCountry.
'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr
ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi
ce='.$ups_dropOffChoice.'&20_destCity='.$delivery_ city_address.'&19_destPost
al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l
ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[
'size_z'];

$html = implode ('', file(urlencode($url)));

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

P: n/a
"Jeff" <je***@ariven.com> wrote in message
news:s07jc.13972$2e6.2485@lakeread01...
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:u6********************************@4ax.com...
I noticed that Message-ID: <4r2jc.13825$2e6.5228@lakeread01> from Jeff
contained the following:
What I seek is an overall resolution to the code sniplet, though, I think
if
I can find out from anyone here on how to fill in any spaces that may existin the $delivery_city_address variable with a %20, that would pretty
muchresolve my issue?


The implode isn't doing it.

http://uk.php.net/manual/en/function.urlencode.php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


Geoff,

Thank you very much for your assistance. I am reading and trying to

gather what I can using the link provided. While I am interested in learning PHP, Im affraid that I might not figure things out until some time has passed.

If you or anyone else wouldn't mind rearranging/modifying the supplied code so that it will work in the case where the city (or any other variable for
that matter I suppose) has a space in it, I would be very much in your debt.
I'll be watching intently to see if someone who doesnt mind doing this for
me, makes the changes.

I try to contribute where I can, unfortunately this is just one of those
NG's I cannot really contribute anything, but rather this is one that Im
visiting strictly as the collector vice contributor. :(


Untested:

$html = implode ('', file
('http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR
esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1
3_product.'&14_origCountry='.urlencode($ups_14_ori gCountry).'&origCity='.url
encode($ups_origCity).
'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.urlencode($ups_22_de
stCountry).
'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr
ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi
ce='.$ups_dropOffChoice.'&20_destCity='.url_encode ($delivery_city_address).'
&19_destPost
al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l
ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[
'size_z']));

- Virgil
Jul 17 '05 #5

P: n/a

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:9r********************************@4ax.com...
I noticed that Message-ID: <s07jc.13972$2e6.2485@lakeread01> from Jeff
contained the following:
Geoff,

Thank you very much for your assistance. I am reading and trying to gatherwhat I can using the link provided. While I am interested in learning PHP,Im affraid that I might not figure things out until some time has passed.
Sorry, from your response I guessed you were more savvy.

Try this: (you will probably have to get rid of the line wraps to make
it work)

$url='http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&d
estR esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1 3_product.'&14_origCountry='.$ups_14_origCountry.' &origCity='.$ups_origCity. '&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.$ups_22_destCountry. '&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi ce='.$ups_dropOffChoice.'&20_destCity='.$delivery_ city_address.'&19_destPost al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[ 'size_z'];

$html = implode ('', file(urlencode($url)));

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


Geoff,

On a good day perhaps, just not today. ;) I am the customer in this
situation, waiting patiently (or trying) for the webmaster to make her
presence known again. What I do know of PHP, I learned in just two days
time, or roughly 48 continous hours, so sleep deprevation is winning the
battle right now.

I'll give that a shot and will be sure to let you know the outcome, but
either way, my appreciation is present. I thank you for taking out time of
your (based upon my assumption of what career field you are in) busy
schedule.

Jeff
Jul 17 '05 #6

P: n/a

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:9r********************************@4ax.com...
I noticed that Message-ID: <s07jc.13972$2e6.2485@lakeread01> from Jeff
contained the following:
Geoff,

Thank you very much for your assistance. I am reading and trying to gatherwhat I can using the link provided. While I am interested in learning PHP,Im affraid that I might not figure things out until some time has passed.
Sorry, from your response I guessed you were more savvy.

Try this: (you will probably have to get rid of the line wraps to make
it work)

$url='http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&d
estR esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1 3_product.'&14_origCountry='.$ups_14_origCountry.' &origCity='.$ups_origCity. '&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.$ups_22_destCountry. '&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi ce='.$ups_dropOffChoice.'&20_destCity='.$delivery_ city_address.'&19_destPost al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[ 'size_z'];

$html = implode ('', file(urlencode($url)));

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Geoff,

Your code didn't do the trick unfortunately. :( Not sure of why it didnt,
but, it instead made every address return an error (more less). Does the
fact that the original code has a @ before the $html have anything to do
with it? Or, do I have to declare $url somewhere?

Thank you for the attempt, Im sure it would have worked in the hands of a
real programmer vice a wannabe :)

Jeff
Jul 17 '05 #7

P: n/a

"Virgil Green" <vj*@obsydian.com> wrote in message
news:%9*****************@newssvr23.news.prodigy.co m...
"Jeff" <je***@ariven.com> wrote in message
news:s07jc.13972$2e6.2485@lakeread01...
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:u6********************************@4ax.com...
I noticed that Message-ID: <4r2jc.13825$2e6.5228@lakeread01> from Jeff
contained the following:

>What I seek is an overall resolution to the code sniplet, though, I think
if
>I can find out from anyone here on how to fill in any spaces that may exist
>in the $delivery_city_address variable with a %20, that would pretty much >resolve my issue?

The implode isn't doing it.

http://uk.php.net/manual/en/function.urlencode.php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


Geoff,

Thank you very much for your assistance. I am reading and trying to

gather
what I can using the link provided. While I am interested in learning

PHP,
Im affraid that I might not figure things out until some time has

passed.
If you or anyone else wouldn't mind rearranging/modifying the supplied

code
so that it will work in the case where the city (or any other variable for that matter I suppose) has a space in it, I would be very much in your

debt.

I'll be watching intently to see if someone who doesnt mind doing this for me, makes the changes.

I try to contribute where I can, unfortunately this is just one of those
NG's I cannot really contribute anything, but rather this is one that Im
visiting strictly as the collector vice contributor. :(


Untested:

$html = implode ('', file

('http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1 3_product.'&14_origCountry='.urlencode($ups_14_ori gCountry).'&origCity='.url encode($ups_origCity).
'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.urlencode($ups_22_de stCountry).
'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi ce='.$ups_dropOffChoice.'&20_destCity='.url_encode ($delivery_city_address).' &19_destPost
al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[ 'size_z']));

- Virgil


Virgil,

This did the trick, thank you very much. A slight error where you have:

&20_destCity='.url_encode.....
vice
&20_destCity='.urlencode...

but, that was easy enough to pin point... it returned a completely blank
page with it as url_encode, which now Im intrigued as to why it does that
<shrug>

Thank you very much everyone. I know I wasn't the easiest to work with (as
ignorant of PHP as I am) so I appreciate the patience.

Jeff

PS - Nope, Im not gone forever. I plan to stick around to learn this PHP
jazz they call programming. ;)
Jul 17 '05 #8

P: n/a
"Jeff" <je***@ariven.com> wrote in message news:4ybjc.2$f_5.0@lakeread01...

"Virgil Green" <vj*@obsydian.com> wrote in message
news:%9*****************@newssvr23.news.prodigy.co m...
"Jeff" <je***@ariven.com> wrote in message
news:s07jc.13972$2e6.2485@lakeread01...

Untested:

$html = implode ('', file

('http://wwwapps.ups.com/ctc/htmlTool?accept_UPS_license_agreement=yes&destR

esident=01&49_residential=1&10_action='.$ups_10_ac tion.'&13_product='.$ups_1

3_product.'&14_origCountry='.urlencode($ups_14_ori gCountry).'&origCity='.url
encode($ups_origCity).

'&15_origPostal='.$ups_15_origPostal.'&22_destCoun try='.urlencode($ups_22_de
stCountry).

'&shipDate='.date("Y-m-d").'&document='.$ups_document.'&currency='.$ups_c urr

ency.'&container='.$ups_container.'&billToUPS='.$u ps_billToUPS.'&dropOffChoi

ce='.$ups_dropOffChoice.'&20_destCity='.url_encode ($delivery_city_address).'
&19_destPost

al='.$delivery_zip.'&23_weight='.$myrow['weight'].'&24_value='.$value.'&25_l

ength='.$myrow['size_x'].'&26_width='.$myrow['size_y'].'&27_height='.$myrow[
'size_z']));

- Virgil


Virgil,

This did the trick, thank you very much. A slight error where you have:

&20_destCity='.url_encode.....
vice
&20_destCity='.urlencode...

but, that was easy enough to pin point... it returned a completely blank
page with it as url_encode, which now Im intrigued as to why it does that
<shrug>

Thank you very much everyone. I know I wasn't the easiest to work with

(as ignorant of PHP as I am) so I appreciate the patience.


You're welcome... and if you think you were "troublesome"... you haven't
seen troublesome. Your question was researched, you showed your code, you
expained what you thought was wrong, and you told us what you expected. That
was refreshing.

Glad to have helped.

- Virgil
Jul 17 '05 #9

P: n/a
I noticed that Message-ID:
<AW*****************@newssvr23.news.prodigy.com> from Virgil Green
contained the following:
You're welcome... and if you think you were "troublesome"... you haven't
seen troublesome. Your question was researched, you showed your code, you
expained what you thought was wrong, and you told us what you expected. That
was refreshing.


I'd agree with that and though I'm pleased I was on the right lines I'm
sorry my effort did not work.

Was I wrong to suggest doing it the way I did?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10

P: n/a
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:mf********************************@4ax.com...
I noticed that Message-ID:
<AW*****************@newssvr23.news.prodigy.com> from Virgil Green
contained the following:
You're welcome... and if you think you were "troublesome"... you haven't
seen troublesome. Your question was researched, you showed your code, you
expained what you thought was wrong, and you told us what you expected. Thatwas refreshing.


I'd agree with that and though I'm pleased I was on the right lines I'm
sorry my effort did not work.

Was I wrong to suggest doing it the way I did?


Only because you were doing the entire URL rather than just the query
string. Your method caused the : and the // of the http:// string to be
replaced as well along with the /s (if there were any) separating host from
directory name information.. and the ? separating the query string from the
rest of the URL. Only the query string (and even then, only parts of it)
needed to be encoded.

However, I picked up the need for the urlencode() function from your post.
Before I saw that, I had decided to skip over the post because I didn't have
time at the moment to decipher it.

- Virgil.
Jul 17 '05 #11

P: n/a
I noticed that Message-ID:
<dg***************@newssvr23.news.prodigy.com> from Virgil Green
contained the following:

Was I wrong to suggest doing it the way I did?
Only because you were doing the entire URL rather than just the query
string. Your method caused the : and the // of the http:// string to be
replaced as well along with the /s (if there were any) separating host from
directory name information.. and the ? separating the query string from the
rest of the URL. Only the query string (and even then, only parts of it)
needed to be encoded.


Hmmm, I thought it would still work. Ah well, you learn something every
day.
However, I picked up the need for the urlencode() function from your post.
Before I saw that, I had decided to skip over the post because I didn't have
time at the moment to decipher it.


Teamwork <g>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.