Re: [PHP] Variables containing HTML?
Since your function stripslashes the data, does that mean that it's not a good idea to use on code that has backslashes? (For instance, if I have some data that I've already run through addslashes or something). Essentially all I'm asking is if it's safe to encode() any string data or just certain kinds of string data. This function is cool -- I was thinking of using it with array_walk() and a bunch of POST data, to get a bunch of numerical strings, then imploding them into a single hidden form field, which on the next instantiation of the page gets exploded back to separate fields and entered into the database. I haven't worked it all out yet, but then again I'm still testing out these functions. Thanks! Erik On Thursday, February 28, 2002, at 07:14 PM, Demitrious S. Kelly wrote: > Consider > > echo serialize('blah'); > ?> > > it returns 's:4:"blah";' > > now, consider > > encode('blah'); > > it returns '098108097104' > > now consider which of the two output strings you end up having to escape > special characters for... > > :) > > > -Original Message- > From: Erik Price [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 28, 2002 1:41 PM > To: Demitrious S. Kelly > Cc: 'Nick Richardson'; 'PHP General' > Subject: Re: [PHP] Variables containing HTML? > > > What's the difference between this and the serialize() function? > > > Erik > > > > > On Monday, February 25, 2002, at 11:27 PM, Demitrious S. Kelly wrote: > >> It breaks the individual characters down into their ascii equivalent, >> and makes it one big 'numerical' string... then breaks the string back >> into separate values and translates each value back into a character, >> then recreates the string from the characters... >> >> I got sick of slashing and un slashing and validating, and > revalidating, >> etc, etc, etc, etc so I made this. Which makes things 1000% simpler >> >> -Original Message- >> From: Nick Richardson [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 8:11 PM >> To: Demitrious S. Kelly; 'PHP General' >> Subject: RE: [PHP] Variables containing HTML? >> >> Right on!!! - This works great!! >> >> Can you explain what it does ;) - i'm completly lost in it ;) >> >> //Nick >> >> -Original Message- >> From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 8:02 PM >> To: 'Nick Richardson'; 'PHP General' >> Subject: RE: [PHP] Variables containing HTML? >> >> >> Try these... >> >> function encode($string) { >> $string=stripslashes($string); >> $temp=''; >> $newstring=''; >> for ( $counter=0; $counter != ; $counter++ ) { >> $temp=substr($string, $counter, 1); >> if ( $temp == '' ) { >> break; >> } >> $newstring=$newstring . str_pad( ord($temp), 3, "0", >> STR_PAD_LEFT); >> } >> return ($newstring); >> } >> >> function decode($string) { >> $temp=''; >> $newstring=''; >> for ( $counter=0; $counter != ; $counter+=3 ) { >> $temp=substr($string, $counter, 3); >> if ( $temp == '' ) { >> break; >> } >> $newstring=$newstring . chr($temp); >> } >> return ($newstring); >> } >> >> -Original Message- >> From: Nick Richardson [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 7:56 PM >> To: PHP General >> Subject: [PHP] Variables containing HTML? >> >> Stupid question for everyone... i'm just having one of those braindead >> moments. >> >> I have a page which allows users to add custom headers and footers in >> HTML. >> (i.e. Fill in a text area with a bunch of html, and that's stored in a >> mysql >> database and retrived when that user logs in again). >> >> The problem i'm having is this: >> >> When a users fills in all the info, and hits submit, they are taken to > a >> preview page which renders everything and has an accept button. >> If i try to store the header and footer data in a hidden input it just >> renders it on the screen (if it's more than one line it
RE: [PHP] Variables containing HTML?
Consider it returns 's:4:"blah";' now, consider encode('blah'); it returns '098108097104' now consider which of the two output strings you end up having to escape special characters for... :) -Original Message- From: Erik Price [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 1:41 PM To: Demitrious S. Kelly Cc: 'Nick Richardson'; 'PHP General' Subject: Re: [PHP] Variables containing HTML? What's the difference between this and the serialize() function? Erik On Monday, February 25, 2002, at 11:27 PM, Demitrious S. Kelly wrote: > It breaks the individual characters down into their ascii equivalent, > and makes it one big 'numerical' string... then breaks the string back > into separate values and translates each value back into a character, > then recreates the string from the characters... > > I got sick of slashing and un slashing and validating, and revalidating, > etc, etc, etc, etc so I made this. Which makes things 1000% simpler > > -Original Message- > From: Nick Richardson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 8:11 PM > To: Demitrious S. Kelly; 'PHP General' > Subject: RE: [PHP] Variables containing HTML? > > Right on!!! - This works great!! > > Can you explain what it does ;) - i'm completly lost in it ;) > > //Nick > > -Original Message----- > From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 8:02 PM > To: 'Nick Richardson'; 'PHP General' > Subject: RE: [PHP] Variables containing HTML? > > > Try these... > > function encode($string) { > $string=stripslashes($string); > $temp=''; > $newstring=''; > for ( $counter=0; $counter != ; $counter++ ) { > $temp=substr($string, $counter, 1); > if ( $temp == '' ) { > break; > } > $newstring=$newstring . str_pad( ord($temp), 3, "0", > STR_PAD_LEFT); > } > return ($newstring); > } > > function decode($string) { > $temp=''; > $newstring=''; > for ( $counter=0; $counter != ; $counter+=3 ) { > $temp=substr($string, $counter, 3); > if ( $temp == '' ) { > break; > } > $newstring=$newstring . chr($temp); > } > return ($newstring); > } > > -Original Message- > From: Nick Richardson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 7:56 PM > To: PHP General > Subject: [PHP] Variables containing HTML? > > Stupid question for everyone... i'm just having one of those braindead > moments. > > I have a page which allows users to add custom headers and footers in > HTML. > (i.e. Fill in a text area with a bunch of html, and that's stored in a > mysql > database and retrived when that user logs in again). > > The problem i'm having is this: > > When a users fills in all the info, and hits submit, they are taken to a > preview page which renders everything and has an accept button. > If i try to store the header and footer data in a hidden input it just > renders it on the screen (if it's more than one line it gets even > worse). > > How can i get this info (variable w/ strings that are QUITE long, and > include quotes and apostrophes) from the form they are entered on, into > a > preview page, then back into the script to be written into the database? > > I have thought about sessions, and they work until the user decides they > dont like the way it turned out and try to discard and change it, even > after > re-registering the variables in the session, they do not change to the > new > input. > > I hope someone out there can make sence of what i have said... because i > think i confused even myself ;) > > Thanks for any help! > > //Nick Richardson > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variables containing HTML?
Erik Price wrote: > > What's the difference between this and the serialize() function? > > Erik It solves a different problem to serialize(). serialize can take pretty much any PHP object / array / data structure and convert it into a string, but the resulting string will still need addslashes() applied to store it in a database and htmlspecialchars() for display in a hidden form field etc. The encode() function takes a PHP string and converts it into a "safe" string which can be put straight in a database / hidden form field / URL variable without needing any further processing - it can then be decoded at a later date. In fact, the encode() and decode() functions would probably complement serialize() very well :) > On Monday, February 25, 2002, at 11:27 PM, Demitrious S. Kelly wrote: > >> It breaks the individual characters down into their ascii equivalent, >> and makes it one big 'numerical' string... then breaks the string back >> into separate values and translates each value back into a character, >> then recreates the string from the characters... >> >> I got sick of slashing and un slashing and validating, and revalidating, >> etc, etc, etc, etc so I made this. Which makes things 1000% simpler >> >> -Original Message- >> From: Nick Richardson [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 8:11 PM >> To: Demitrious S. Kelly; 'PHP General' >> Subject: RE: [PHP] Variables containing HTML? >> >> Right on!!! - This works great!! >> >> Can you explain what it does ;) - i'm completly lost in it ;) >> >> //Nick >> >> -----Original Message----- >> From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 8:02 PM >> To: 'Nick Richardson'; 'PHP General' >> Subject: RE: [PHP] Variables containing HTML? >> >> >> Try these... >> >> function encode($string) { >> $string=stripslashes($string); >> $temp=''; >> $newstring=''; >> for ( $counter=0; $counter != ; $counter++ ) { >> $temp=substr($string, $counter, 1); >> if ( $temp == '' ) { >> break; >> } >> $newstring=$newstring . str_pad( ord($temp), 3, "0", >> STR_PAD_LEFT); >> } >> return ($newstring); >> } >> >> function decode($string) { >> $temp=''; >> $newstring=''; >> for ( $counter=0; $counter != ; $counter+=3 ) { >> $temp=substr($string, $counter, 3); >> if ( $temp == '' ) { >> break; >> } >> $newstring=$newstring . chr($temp); >> } >> return ($newstring); >> } >> >> -Original Message- >> From: Nick Richardson [mailto:[EMAIL PROTECTED]] >> Sent: Monday, February 25, 2002 7:56 PM >> To: PHP General >> Subject: [PHP] Variables containing HTML? >> >> Stupid question for everyone... i'm just having one of those braindead >> moments. >> >> I have a page which allows users to add custom headers and footers in >> HTML. >> (i.e. Fill in a text area with a bunch of html, and that's stored in a >> mysql >> database and retrived when that user logs in again). >> >> The problem i'm having is this: >> >> When a users fills in all the info, and hits submit, they are taken to a >> preview page which renders everything and has an accept button. >> If i try to store the header and footer data in a hidden input it just >> renders it on the screen (if it's more than one line it gets even >> worse). >> >> How can i get this info (variable w/ strings that are QUITE long, and >> include quotes and apostrophes) from the form they are entered on, into >> a >> preview page, then back into the script to be written into the database? >> >> I have thought about sessions, and they work until the user decides they >> dont like the way it turned out and try to discard and change it, even >> after >> re-registering the variables in the session, they do not change to the >> new >> input. >> >> I hope someone out there can make sence of what i have said... because i >> think i confused even myself ;) >> >> Thanks for any help! >> >> //Nick Richardson >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > > > > > > Erik Price > Web Developer Temp > Media Lab, H.H. Brown > [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variables containing HTML?
What's the difference between this and the serialize() function? Erik On Monday, February 25, 2002, at 11:27 PM, Demitrious S. Kelly wrote: > It breaks the individual characters down into their ascii equivalent, > and makes it one big 'numerical' string... then breaks the string back > into separate values and translates each value back into a character, > then recreates the string from the characters... > > I got sick of slashing and un slashing and validating, and revalidating, > etc, etc, etc, etc so I made this. Which makes things 1000% simpler > > -Original Message- > From: Nick Richardson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 8:11 PM > To: Demitrious S. Kelly; 'PHP General' > Subject: RE: [PHP] Variables containing HTML? > > Right on!!! - This works great!! > > Can you explain what it does ;) - i'm completly lost in it ;) > > //Nick > > -Original Message- > From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 8:02 PM > To: 'Nick Richardson'; 'PHP General' > Subject: RE: [PHP] Variables containing HTML? > > > Try these... > > function encode($string) { > $string=stripslashes($string); > $temp=''; > $newstring=''; > for ( $counter=0; $counter != ; $counter++ ) { > $temp=substr($string, $counter, 1); > if ( $temp == '' ) { > break; > } > $newstring=$newstring . str_pad( ord($temp), 3, "0", > STR_PAD_LEFT); > } > return ($newstring); > } > > function decode($string) { > $temp=''; > $newstring=''; > for ( $counter=0; $counter != ; $counter+=3 ) { > $temp=substr($string, $counter, 3); > if ( $temp == '' ) { > break; > } > $newstring=$newstring . chr($temp); > } > return ($newstring); > } > > -Original Message- > From: Nick Richardson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 25, 2002 7:56 PM > To: PHP General > Subject: [PHP] Variables containing HTML? > > Stupid question for everyone... i'm just having one of those braindead > moments. > > I have a page which allows users to add custom headers and footers in > HTML. > (i.e. Fill in a text area with a bunch of html, and that's stored in a > mysql > database and retrived when that user logs in again). > > The problem i'm having is this: > > When a users fills in all the info, and hits submit, they are taken to a > preview page which renders everything and has an accept button. > If i try to store the header and footer data in a hidden input it just > renders it on the screen (if it's more than one line it gets even > worse). > > How can i get this info (variable w/ strings that are QUITE long, and > include quotes and apostrophes) from the form they are entered on, into > a > preview page, then back into the script to be written into the database? > > I have thought about sessions, and they work until the user decides they > dont like the way it turned out and try to discard and change it, even > after > re-registering the variables in the session, they do not change to the > new > input. > > I hope someone out there can make sence of what i have said... because i > think i confused even myself ;) > > Thanks for any help! > > //Nick Richardson > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variables containing HTML?
It breaks the individual characters down into their ascii equivalent, and makes it one big 'numerical' string... then breaks the string back into separate values and translates each value back into a character, then recreates the string from the characters... I got sick of slashing and un slashing and validating, and revalidating, etc, etc, etc, etc so I made this. Which makes things 1000% simpler -Original Message- From: Nick Richardson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 8:11 PM To: Demitrious S. Kelly; 'PHP General' Subject: RE: [PHP] Variables containing HTML? Right on!!! - This works great!! Can you explain what it does ;) - i'm completly lost in it ;) //Nick -Original Message- From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 8:02 PM To: 'Nick Richardson'; 'PHP General' Subject: RE: [PHP] Variables containing HTML? Try these... function encode($string) { $string=stripslashes($string); $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter++ ) { $temp=substr($string, $counter, 1); if ( $temp == '' ) { break; } $newstring=$newstring . str_pad( ord($temp), 3, "0", STR_PAD_LEFT); } return ($newstring); } function decode($string) { $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter+=3 ) { $temp=substr($string, $counter, 3); if ( $temp == '' ) { break; } $newstring=$newstring . chr($temp); } return ($newstring); } -Original Message- From: Nick Richardson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 7:56 PM To: PHP General Subject: [PHP] Variables containing HTML? Stupid question for everyone... i'm just having one of those braindead moments. I have a page which allows users to add custom headers and footers in HTML. (i.e. Fill in a text area with a bunch of html, and that's stored in a mysql database and retrived when that user logs in again). The problem i'm having is this: When a users fills in all the info, and hits submit, they are taken to a preview page which renders everything and has an accept button. If i try to store the header and footer data in a hidden input it just renders it on the screen (if it's more than one line it gets even worse). How can i get this info (variable w/ strings that are QUITE long, and include quotes and apostrophes) from the form they are entered on, into a preview page, then back into the script to be written into the database? I have thought about sessions, and they work until the user decides they dont like the way it turned out and try to discard and change it, even after re-registering the variables in the session, they do not change to the new input. I hope someone out there can make sence of what i have said... because i think i confused even myself ;) Thanks for any help! //Nick Richardson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variables containing HTML?
Right on!!! - This works great!! Can you explain what it does ;) - i'm completly lost in it ;) //Nick -Original Message- From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 8:02 PM To: 'Nick Richardson'; 'PHP General' Subject: RE: [PHP] Variables containing HTML? Try these... function encode($string) { $string=stripslashes($string); $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter++ ) { $temp=substr($string, $counter, 1); if ( $temp == '' ) { break; } $newstring=$newstring . str_pad( ord($temp), 3, "0", STR_PAD_LEFT); } return ($newstring); } function decode($string) { $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter+=3 ) { $temp=substr($string, $counter, 3); if ( $temp == '' ) { break; } $newstring=$newstring . chr($temp); } return ($newstring); } -Original Message- From: Nick Richardson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 7:56 PM To: PHP General Subject: [PHP] Variables containing HTML? Stupid question for everyone... i'm just having one of those braindead moments. I have a page which allows users to add custom headers and footers in HTML. (i.e. Fill in a text area with a bunch of html, and that's stored in a mysql database and retrived when that user logs in again). The problem i'm having is this: When a users fills in all the info, and hits submit, they are taken to a preview page which renders everything and has an accept button. If i try to store the header and footer data in a hidden input it just renders it on the screen (if it's more than one line it gets even worse). How can i get this info (variable w/ strings that are QUITE long, and include quotes and apostrophes) from the form they are entered on, into a preview page, then back into the script to be written into the database? I have thought about sessions, and they work until the user decides they dont like the way it turned out and try to discard and change it, even after re-registering the variables in the session, they do not change to the new input. I hope someone out there can make sence of what i have said... because i think i confused even myself ;) Thanks for any help! //Nick Richardson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variables containing HTML?
Try these... function encode($string) { $string=stripslashes($string); $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter++ ) { $temp=substr($string, $counter, 1); if ( $temp == '' ) { break; } $newstring=$newstring . str_pad( ord($temp), 3, "0", STR_PAD_LEFT); } return ($newstring); } function decode($string) { $temp=''; $newstring=''; for ( $counter=0; $counter != ; $counter+=3 ) { $temp=substr($string, $counter, 3); if ( $temp == '' ) { break; } $newstring=$newstring . chr($temp); } return ($newstring); } -Original Message- From: Nick Richardson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 25, 2002 7:56 PM To: PHP General Subject: [PHP] Variables containing HTML? Stupid question for everyone... i'm just having one of those braindead moments. I have a page which allows users to add custom headers and footers in HTML. (i.e. Fill in a text area with a bunch of html, and that's stored in a mysql database and retrived when that user logs in again). The problem i'm having is this: When a users fills in all the info, and hits submit, they are taken to a preview page which renders everything and has an accept button. If i try to store the header and footer data in a hidden input it just renders it on the screen (if it's more than one line it gets even worse). How can i get this info (variable w/ strings that are QUITE long, and include quotes and apostrophes) from the form they are entered on, into a preview page, then back into the script to be written into the database? I have thought about sessions, and they work until the user decides they dont like the way it turned out and try to discard and change it, even after re-registering the variables in the session, they do not change to the new input. I hope someone out there can make sence of what i have said... because i think i confused even myself ;) Thanks for any help! //Nick Richardson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variables containing HTML?
there's htmlentities or something like that - try that w/ your hidden field -Original Message- From: Nick Richardson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 26, 2002 2:56 PM To: PHP General Subject: [PHP] Variables containing HTML? Stupid question for everyone... i'm just having one of those braindead moments. I have a page which allows users to add custom headers and footers in HTML. (i.e. Fill in a text area with a bunch of html, and that's stored in a mysql database and retrived when that user logs in again). The problem i'm having is this: When a users fills in all the info, and hits submit, they are taken to a preview page which renders everything and has an accept button. If i try to store the header and footer data in a hidden input it just renders it on the screen (if it's more than one line it gets even worse). How can i get this info (variable w/ strings that are QUITE long, and include quotes and apostrophes) from the form they are entered on, into a preview page, then back into the script to be written into the database? I have thought about sessions, and they work until the user decides they dont like the way it turned out and try to discard and change it, even after re-registering the variables in the session, they do not change to the new input. I hope someone out there can make sence of what i have said... because i think i confused even myself ;) Thanks for any help! //Nick Richardson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php