473,626 Members | 3,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct string-split and reassemble?

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=subs tr($questions, 0, 3556); // I put a limit on the total
string size.

$questions0=sub str($questions, 0, 254);
$questions1=sub str($questions, 254, 254);
$questions2=sub str($questions, 508, 254);
$questions3=sub str($questions, 762, 254); // etc.

<INPUT TYPE="HIDDEN" NAME="questions 0" value="<?=$ques tions0?>" >
<INPUT TYPE="HIDDEN" NAME="questions 1" value="<?=$ques tions1?>" >
<INPUT TYPE="HIDDEN" NAME="questions 2" value="<?=$ques tions2?>" >
<INPUT TYPE="HIDDEN" NAME="questions 3" value="<?=$ques tions3?>" > //
etc.

Then I POST the data, and then it comes back to my redirect page, which
uses the following code:

$questions0=$_P OST['questions0'];
$questions1=$_P OST['questions1'];
$questions2=$_P OST['questions2'];
$questions3=$_P OST['questions3']; // etc.

$questions=$que stions0 . $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.

Jul 17 '05 #1
3 1858
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_va r), so if you have any spaces in the input remove it
before any other process.
-----------------------------------------
but you may can concatenate your text using implode(".",$va raible)
if your still in problem let me know we may also use REGEXP to check
the data, see u.

Jul 17 '05 #2
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_gp c" 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=sub str($questions, 0, 254);
$questions1=sub str($questions, 254, 254);
$questions2=sub str($questions, 508, 254);
$questions3=sub str($questions, 762, 254); // etc.
Ugh!

define('CHUNK_S IZE', 254);
$chunks = 1 + strlen($questio ns)/CHUNK_SIZE;
for ($i = 0; $i < $chunks; ++$i) {
/* using variable variables */
$q = 'questions' . $i;
$$q = substr($questio ns, CHUNK_SIZE * $i, CHUNK_SIZE);
}
IMO, even better would be to use arrays:

define('CHUNK_S IZE', 254);
$qs = array();
$chunks = 1 + strlen($questio ns)/CHUNK_SIZE;
for ($i = 0; $i < $chunks; ++$i) {
$qs[] = substr($questio ns, CHUNK_SIZE * $i, CHUNK_SIZE);
}
<INPUT TYPE="HIDDEN" NAME="questions 0" value="<?=$ques tions0?>" >
<INPUT TYPE="HIDDEN" NAME="questions 1" value="<?=$ques tions1?>" >
<INPUT TYPE="HIDDEN" NAME="questions 2" value="<?=$ques tions2?>" >
<INPUT TYPE="HIDDEN" NAME="questions 3" value="<?=$ques tions3?>" > //
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=$que stions0 . $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!
Jul 17 '05 #3
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=subs tr($questions, 0, 3556); // I put a limit on the total
string size.

$questions0=sub str($questions, 0, 254);
$questions1=sub str($questions, 254, 254);
$questions2=sub str($questions, 508, 254);
$questions3=sub str($questions, 762, 254); // etc.
$i=0;
while(strlen($q uestion) > 255) {
$curstr = substr($questio ns, 0, 254);
Now cut the first 255 characters from $questions
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"question s$i\" value=\"$curstr \">\n";
$i++
}

<INPUT TYPE="HIDDEN" NAME="questions 0" value="<?=$ques tions0?>" >
<INPUT TYPE="HIDDEN" NAME="questions 1" value="<?=$ques tions1?>" >
<INPUT TYPE="HIDDEN" NAME="questions 2" value="<?=$ques tions2?>" >
<INPUT TYPE="HIDDEN" NAME="questions 3" value="<?=$ques tions3?>" > //
etc.

Then I POST the data, and then it comes back to my redirect page, which
uses the following code:

$questions0=$_P OST['questions0'];
$questions1=$_P OST['questions1'];
$questions2=$_P OST['questions2'];
$questions3=$_P OST['questions3']; // etc.

$questions=$que stions0 . $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.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3014
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 Japanese I can just print the string and see the correct results. However, I don't know how to get Python to do the right thing for writing systems which require contextual processing. For example, let's say I create this Unicode string in Arabic: ...
27
2062
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 seen such syntax in
6
3479
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 correct output is that r = EOF. If it is taken to be a letter in the stream, then the output should be r = 0, as far as I can see. My compiler gives EOF.
0
768
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 error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 457: <tr>
5
2507
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 not in the correct format. 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 error and where it...
1
2844
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 = request.QueryString("enddate") Line 20: Line 21: if cint(eventid) = "0" then
0
3160
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 consists of a label control(hidden when run in browser). Also an Sql data source control connected to database tables for a photo album. Also label web control ID=UserIdValue. Also a Details View control ID=dvPictureInsert Problem is how to work out...
1
4517
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 Photoadmin/default.aspx i got the following message and info. 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...
1
4754
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 THE PROGRAM PLEASE HELP ME Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Input string was not in a correct format. Description: An unhandled exception occurred...
3
1333
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> <add key="Connection" value="server=.;trusted_connection=true;initial catalog=sanjay"/> </appSettings></configuration> Inside Data Access Layer private string username; private string password; public string UserName
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.