/    Sign up×
Community /Pin to ProfileBookmark

how do i modify this?

I have this:

print(“<input type=hidden name=class value=”.urlencode($HTTP_GET_VARS[‘class’]).”>rn”);

it returns this when i call it from the next page:

Jun+1+2005+12%3A00AM

I call it with this:
mail( “[email protected]“, “$class”,
“Name: $name rnrnDepartment: $deptrnrnLocation: $loc”);

The class is actually:
IFR 1 Yr Re-Certification, June 1/05 (in the data base)

What am I doing wrong?
THANKS!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MarkLMay 25.2005 — I am not sure why it is truncating the part of the variable before the comma, and skipping the witespace, but urlencode() is doing exactly what it is supposed to do with the remaining portion.

This is a blurb from php.net on urlencode():

"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs."

Are you sure the first half of your string was not stripped from the variable prior to using this function?
Copy linkTweet thisAlerts:
@sanjuTauthorMay 25.2005 — I am not sure why it is truncating the part of the variable before the comma, and skipping the witespace, but urlencode() is doing exactly what it is supposed to do with the remaining portion.

This is a blurb from php.net on urlencode():

"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs."

Are you sure the first half of your string was not stripped from the variable prior to using this function?[/QUOTE]


i looked at other parts of the code, and found it was inserting into the data base as:

urldecode($HTTP_GET_VARS['class'])

so i used this:

mail( "[email protected]", urldecode($HTTP_GET_VARS['class']),

"Name: $name rnrnDepartment: $deptrnrnLocation: $loc");

and now it returns this:

Jun 1 2005 12:00AM

How can I strip off the 12:00AM, or alter it? Either is usable.

THANKS!
Copy linkTweet thisAlerts:
@MarkLMay 26.2005 — You can use the substr() function to return the portion of the string you want to keep. The position and the length of the string portion need to be predictable, however. In the date format you are using, it should be predictable, but it will vary, so you will need to take that into account. Here is one way you might be able to do it:

[code=php]<? php
$ex_string = "Jun 1 2005 12:00AM"; //this string is 18 characters long, but it could be 1 character longer given a 2 digit number for the day
$str_size = strlen($ex_string); //returns the number of characters in the string
switch ($str_size)
{
case 18:
$short_string = substr($ex_string, 0, 10); //char position in the string starts at 0 and the portion we need to return is 10 chars
break;
case 19:
$short_string = substr($ex_string, 0, 11); //if the day is 2 chars the portion we need will be 11 chars
break;
}
//$short_string now holds only the original string minus the time portion
?>[/code]


I used a switch statement here just in case there are other variances in the length of the string, it will be easier to add the code to account for them. You may also want to use the ltrim() function to remove any leading whitespace if that is a concern.
×

Success!

Help @sanjuT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...