Hello,
Can anyone help with this code?
I need to split a long piece of text from a textarea box into small
chunks, then POST these chunks to my credit-card provider, whereupon he
will POST them back to my script, which will reassemble them into the
original text and display it. This is necessary because my credit-card
provider has a limit on all POSTed variables, which must be 255
characters or less each.
I thought that this would be simple to do. I used substr to take bites
out of the string, then included each piece as a hidden variable in my
form. When I received the return POST, I reassembled all the strings
using the (.) concatenator, then printed this out.
The problem is, pieces of the original text are missing, and there are
numerous // escape elements present in the text.
Here is my code:
$questions = $_POST['questions']; // coming from a previous POST
$questions=substr($questions, 0, 3556); // I put a limit on the total
string size.
$questions0=substr($questions, 0, 254);
$questions1=substr($questions, 254, 254);
$questions2=substr($questions, 508, 254);
$questions3=substr($questions, 762, 254); // etc.
<INPUT TYPE="HIDDEN" NAME="questions0" value="<?=$questions0?>" >
<INPUT TYPE="HIDDEN" NAME="questions1" value="<?=$questions1?>" >
<INPUT TYPE="HIDDEN" NAME="questions2" value="<?=$questions2?>" >
<INPUT TYPE="HIDDEN" NAME="questions3" value="<?=$questions3?>" > //
etc.
Then I POST the data, and then it comes back to my redirect page, which
uses the following code:
$questions0=$_POST['questions0'];
$questions1=$_POST['questions1'];
$questions2=$_POST['questions2'];
$questions3=$_POST['questions3']; // etc.
$questions=$questions0 . $questions1 . $questions2 . $questions3 .
$questions4 . $questions5 . $questions6 . $questions7 . $questions8 .
$questions9 . $questions10 . $questions11 . $questions12 . $questions13
.. $questions14; // concatenate it
print ($questions); // I display $questions. It is mostly there, with
parts missing, and many //s here and there.
Any ideas?
Thank you. 3 1848
hi , iam not sure of your algorithm , but i need to see the valid form
of the credit-card that can be accepted by your provider ,
now i may hint somthing
while you are using textarea i think you have to be sure of the spaces:
1-trim the input form both sides (left,rgiht) using
trim($_POST['your_quiz']).
2-make sure there is no inner spaces in the input using
strpos($your_var), so if you have any spaces in the input remove it
before any other process.
-----------------------------------------
but you may can concatenate your text using implode(".",$varaible)
if your still in problem let me know we may also use REGEXP to check
the data, see u.
Robert wrote: The problem is, pieces of the original text are missing, and there are numerous // escape elements present in the text.
Do you mean extra \ (backslashes)?
I suspect you (or the credit-card provider) are running with
"magic_qutes_gpc" set.
Either turn them off or stripslashes() from the input. http://www.php.net/manual/en/function.stripslashes.php
A few comments about your code (snippets not tested):
$questions0=substr($questions, 0, 254); $questions1=substr($questions, 254, 254); $questions2=substr($questions, 508, 254); $questions3=substr($questions, 762, 254); // etc.
Ugh!
define('CHUNK_SIZE', 254);
$chunks = 1 + strlen($questions)/CHUNK_SIZE;
for ($i = 0; $i < $chunks; ++$i) {
/* using variable variables */
$q = 'questions' . $i;
$$q = substr($questions, CHUNK_SIZE * $i, CHUNK_SIZE);
}
IMO, even better would be to use arrays:
define('CHUNK_SIZE', 254);
$qs = array();
$chunks = 1 + strlen($questions)/CHUNK_SIZE;
for ($i = 0; $i < $chunks; ++$i) {
$qs[] = substr($questions, CHUNK_SIZE * $i, CHUNK_SIZE);
}
<INPUT TYPE="HIDDEN" NAME="questions0" value="<?=$questions0?>" > <INPUT TYPE="HIDDEN" NAME="questions1" value="<?=$questions1?>" > <INPUT TYPE="HIDDEN" NAME="questions2" value="<?=$questions2?>" > <INPUT TYPE="HIDDEN" NAME="questions3" value="<?=$questions3?>" > // etc.
Using the $qs array:
$n = 0; /* probably not needed, see ## below */
foreach ($qs as $q) {
/* when the for with these inputs is submitted */
/* $_POST['questions'] will be an array */
echo '<input type="hidden" name="questions[', $n++, ']" value="', $q, '"/>';
/* if you want to try it without the $n */
## echo '<input type="hidden" name="questions[]" value="', $q, '"/>';
}
Then I POST the data, and then it comes back to my redirect page, which uses the following code:
$questions=$questions0 . $questions1 . $questions2 . $questions3 . $questions4 . $questions5 . $questions6 . $questions7 . $questions8 . $questions9 . $questions10 . $questions11 . $questions12 . $questions13 . $questions14; // concatenate it
$questions = implode('', $_POST['questions']);
print ($questions); // I display $questions. It is mostly there, with parts missing, and many //s here and there.
Happy Coding :-)
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
An noise sounding like Robert said: Hello,
Can anyone help with this code?
I need to split a long piece of text from a textarea box into small chunks, then POST these chunks to my credit-card provider, whereupon he will POST them back to my script, which will reassemble them into the original text and display it. This is necessary because my credit-card provider has a limit on all POSTed variables, which must be 255 characters or less each.
I thought that this would be simple to do. I used substr to take bites out of the string, then included each piece as a hidden variable in my form. When I received the return POST, I reassembled all the strings using the (.) concatenator, then printed this out.
The problem is, pieces of the original text are missing, and there are numerous // escape elements present in the text.
Here is my code:
$questions = $_POST['questions']; // coming from a previous POST
$questions=substr($questions, 0, 3556); // I put a limit on the total string size.
$questions0=substr($questions, 0, 254); $questions1=substr($questions, 254, 254); $questions2=substr($questions, 508, 254); $questions3=substr($questions, 762, 254); // etc.
$i=0;
while(strlen($question) > 255) {
$curstr = substr($questions, 0, 254);
Now cut the first 255 characters from $questions
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"questions$i\" value=\"$curstr\">\n";
$i++
}
<INPUT TYPE="HIDDEN" NAME="questions0" value="<?=$questions0?>" > <INPUT TYPE="HIDDEN" NAME="questions1" value="<?=$questions1?>" > <INPUT TYPE="HIDDEN" NAME="questions2" value="<?=$questions2?>" > <INPUT TYPE="HIDDEN" NAME="questions3" value="<?=$questions3?>" > // etc.
Then I POST the data, and then it comes back to my redirect page, which uses the following code:
$questions0=$_POST['questions0']; $questions1=$_POST['questions1']; $questions2=$_POST['questions2']; $questions3=$_POST['questions3']; // etc.
$questions=$questions0 . $questions1 . $questions2 . $questions3 . $questions4 . $questions5 . $questions6 . $questions7 . $questions8 . $questions9 . $questions10 . $questions11 . $questions12 . $questions13 . $questions14; // concatenate it
print ($questions); // I display $questions. It is mostly there, with parts missing, and many //s here and there.
$i=0;
$varName = "questions".$i;
do{
$questions .= $_POST['$varName'];
$i++;
$varName = "questions".$i;
}while($_POST['$varName'])
Or something along those lines is a much neater way of doing what you want to
do. You're going to have to strip slashes yourself. www.php.net/stripslashes
db
--
/(bb|[^b]{2})/
Trees with square roots don't have very natural logs. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Opstad |
last post by:
I have a question about text rendering I'm hoping someone here can
answer. Is there a way of doing linguistically correct rendering of
Unicode strings in Python? In simple cases like Latin or...
|
by: Yang Lee |
last post by:
Hi,
If I write
char *p="hello world";
is this correct in C or do i have to assign memory block and then
strcpy the string to pointer.
If not correct in C , is it allowable in C++ , i...
|
by: Rob Thorpe |
last post by:
Given the code:-
r = sscanf (s, "%lf", x);
What is the correct output if the string s is simply "-" ?
If "-" is considered the beginning of a number, that has been
cut-short then the...
|
by: lianfe_ravago |
last post by:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the...
|
by: blackg |
last post by:
Input string not in correct format
--------------------------------------------------------------------------------
I am trying to view a picture from a table. I am getting this error
Input string...
|
by: amitbadgi |
last post by:
I am gettign this error, while migration an app to asp.net
Exception Details: System.FormatException: Input string was not in a
correct format.
Source Error:
Line 19: Dim enddate =...
|
by: sehguh |
last post by:
Hiya Folks,
I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005.
The main page consists of an aspx page and a master page.
The page also...
|
by: sehguh |
last post by:
Hello folks
I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
|
by: differentsri |
last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT?
CAN U TELL THE REASON ?
IT IS GIVING THE FOLLOWING ERROR
BELOW I HAVE ALSO GIVEN THE CODE OF...
|
by: raghulvarma |
last post by:
I did a small sample with three tier architecture and i need to know whether the flow of the program is correct or not.The pgm works fine.
Inside web.config
<configuration> <appSettings> ...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |