php-general Digest 7 Oct 2006 23:50:04 -0000 Issue 4388
php-general Digest 7 Oct 2006 23:50:04 - Issue 4388 Topics (messages 242796 through 242804): Re: Testing people 242796 by: Ryan A Re: Unicode Problem 242797 by: tedd Re: Set Variable = Long HTML String? 242798 by: sit1way 242799 by: John Wells 242800 by: David Tulloh 242801 by: John Wells Re: set cookie with non-english 242802 by: Ahmad Al-Twaijiry Re: Separate PHP Code From HTML || Pros Cons? 242803 by: sit1way FTP 242804 by: Raphael Martins Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: php-general@lists.php.net -- ---BeginMessage--- Thanks! Will give it a look-see! Cheers! Dotan Cohen [EMAIL PROTECTED] wrote: It's not exactly what you describe, but you should take a look at: http://www.bigredspark.com/survey.html Dotan Cohen http://what-is-what.com 7 -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) - Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1cent;/min.---End Message--- ---BeginMessage--- At 4:15 PM -0500 10/6/06, Richard Lynch wrote: Perhaps you would care to extend your browsercam test to some regression testing of more ancient browsers -- on Mac OS. The following goes back to IE 5.2 for the Mac -- that's as far back as BrowserCam goes. http://www.browsercam.com/public.aspx?proj_id=289683 I think you meant x2022 a.k.a. (dec)8226 :-) Ahh, a typo thanks. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com ---End Message--- ---BeginMessage--- Hey all. I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! Example: $var = form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selectedNews Options/option option value=? echo $this-doc_path ?admin/news/add/1/Add/option option value=? echo $this-doc_path ?admin/news/update/1/Update/option option value=? echo $this-doc_path ?admin/news/delete/1/Delete/option /select /form; This will die due to all the unescaped strings, not to mention the ? echo $this-doc_path ? statements. How to pull this off? I don't want to include the HTML snippets as they are sprinkled throughout my classes. TIA, --Noah ---End Message--- ---BeginMessage--- On 10/7/06, sit1way [EMAIL PROTECTED] wrote: I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! Noah, meet HEREDOC. HEREDOC, meet Noah: http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Now you cozy two, let's make it a party with the Complex (Curly {}) syntax: http://uk.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex All together now! [code] $var =HEREDOC form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selected=selectedNews Options/option option value={$this-doc_path}admin/news/add/1/Add/option option value={$this-doc_path}admin/news/update/1/Update/option option value={$this-doc_path}admin/news/delete/1/Delete/option /select /form HEREDOC; [/code] HTH, John W TIA, --Noah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- You can mingle double and singal quotes. So choose one for the PHP quotes and one for the HTML quotes, HTML will use both interchangably. For example your string could become: $var = form name='events' ...; I'd also look at the echo's inside the string, they look like they shouldn't be there. David sit1way wrote: Hey all. I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! You can mingle double and singal quotes. So choose one for the PHP quotes and one for the HTML quotes, HTML will use both interchangably. For example your string could become: $var = form name='events' ...; The echo's inside the string also aren't necessary. Just use the value directly when building the string. David Example: $var = form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selectedNews Options/option option value=? echo $this-doc_path ?admin/news/add/1/Add/option option value=? echo
Re: [PHP] Testing people
Thats why I love this list... people share and help so unselfishly. Thanks Rich, sure didnt think of the way you wrote the solution till i read your code! Have a fab one! Richard Lynch [EMAIL PROTECTED] wrote: I thought of having a hidden text box everytime for each question... but that can be quite easily found out... any other suggestions? Don't send the correct answer to the browser at all. And don't tie the ABCD to the correct answer. $question[47] = Which animal flies around at night and sleeps in the day? $answer[13] = 'cat'; $answer[14] = 'dog'; $answer[15] = 'trout'; $answer[16] = 'bat'; $correct[47] = 'bat'; ? Your HTML could look like this: A [input] cat B [input] dog C [input] trout D [input] bat To test if the answer is correct: $q = $_REQUEST['q']; foreach($q as $index = $a){ if ($correct[$index] == $a) echo CORRECT; else echo INCORRECT: Correct is $correct[$index]; echo \n; } You could also use the index to $answer as the value with: $correct[47] = 16; [input] bat if ($correct[$index] == $a){ and all the other code the same. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) - Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
Re: [PHP] Testing people
Thanks! Will give it a look-see! Cheers! Dotan Cohen [EMAIL PROTECTED] wrote: It's not exactly what you describe, but you should take a look at: http://www.bigredspark.com/survey.html Dotan Cohen http://what-is-what.com 7 -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) - Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1cent;/min.
RE: [PHP] Unicode Problem
At 4:15 PM -0500 10/6/06, Richard Lynch wrote: Perhaps you would care to extend your browsercam test to some regression testing of more ancient browsers -- on Mac OS. The following goes back to IE 5.2 for the Mac -- that's as far back as BrowserCam goes. http://www.browsercam.com/public.aspx?proj_id=289683 I think you meant x2022 a.k.a. (dec)8226 :-) Ahh, a typo thanks. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Set Variable = Long HTML String?
Hey all. I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! Example: $var = form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selectedNews Options/option option value=? echo $this-doc_path ?admin/news/add/1/Add/option option value=? echo $this-doc_path ?admin/news/update/1/Update/option option value=? echo $this-doc_path ?admin/news/delete/1/Delete/option /select /form; This will die due to all the unescaped strings, not to mention the ? echo $this-doc_path ? statements. How to pull this off? I don't want to include the HTML snippets as they are sprinkled throughout my classes. TIA, --Noah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Set Variable = Long HTML String?
On 10/7/06, sit1way [EMAIL PROTECTED] wrote: I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! Noah, meet HEREDOC. HEREDOC, meet Noah: http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Now you cozy two, let's make it a party with the Complex (Curly {}) syntax: http://uk.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex All together now! [code] $var =HEREDOC form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selected=selectedNews Options/option option value={$this-doc_path}admin/news/add/1/Add/option option value={$this-doc_path}admin/news/update/1/Update/option option value={$this-doc_path}admin/news/delete/1/Delete/option /select /form HEREDOC; [/code] HTH, John W TIA, --Noah -- 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] Re: Set Variable = Long HTML String?
You can mingle double and singal quotes. So choose one for the PHP quotes and one for the HTML quotes, HTML will use both interchangably. For example your string could become: $var = form name='events' ...; I'd also look at the echo's inside the string, they look like they shouldn't be there. David sit1way wrote: Hey all. I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! You can mingle double and singal quotes. So choose one for the PHP quotes and one for the HTML quotes, HTML will use both interchangably. For example your string could become: $var = form name='events' ...; The echo's inside the string also aren't necessary. Just use the value directly when building the string. David Example: $var = form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selectedNews Options/option option value=? echo $this-doc_path ?admin/news/add/1/Add/option option value=? echo $this-doc_path ?admin/news/update/1/Update/option option value=? echo $this-doc_path ?admin/news/delete/1/Delete/option /select /form; This will die due to all the unescaped strings, not to mention the ? echo $this-doc_path ? statements. How to pull this off? I don't want to include the HTML snippets as they are sprinkled throughout my classes. TIA, --Noah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Set Variable = Long HTML String?
On 10/7/06, Noah Cutler [EMAIL PROTECTED] wrote: Yah, John. Just found it via Google. I remembered seeing this somewhere a couple years back but never used it. Very cool -- performance hit using this, or just a really useful function? From what I understand it suffers the same hit as double quotes, since PHP has to parse it looking for variables. But it's not really special, it's just not as well known. - John W Thanks, --Noah - Original Message - From: John Wells [EMAIL PROTECTED] To: sit1way [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Saturday, October 07, 2006 12:03 PM Subject: Re: [PHP] Re: Set Variable = Long HTML String? On 10/7/06, sit1way [EMAIL PROTECTED] wrote: I'm overhauling my PHP based CMS and want to know how to set a variable equal to an HTML string, but without having to escape all the quotes! Noah, meet HEREDOC. HEREDOC, meet Noah: http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Now you cozy two, let's make it a party with the Complex (Curly {}) syntax: http://uk.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex All together now! [code] $var =HEREDOC form name=events method=POST action= select class=menus name=news onChange=MM_jumpMenu('parent',this,0); option selected=selectedNews Options/option option value={$this-doc_path}admin/news/add/1/Add/option option value={$this-doc_path}admin/news/update/1/Update/option option value={$this-doc_path}admin/news/delete/1/Delete/option /select /form HEREDOC; [/code] HTH, John W TIA, --Noah -- 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] set cookie with non-english
BTW I want to access the (cookie or session) variable from php javascript, so I don't think session is a solution so again, does anyone know how to resolve the problem so I can write the cookie output to UTF-8 html page ? On 10/5/06, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, October 3, 2006 11:18 pm, Ahmad Al-Twaijiry wrote: I already made the application with cookies, it's will be very defaucalt to go and replace cookies with session, is it possible to use cookies session in the same time ? ( session_start() setcookie in the same page ?) Sure... Though if it's hard to convert your Cookies code to session_start() you've done something very wrong already... ;-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- Ahmad Fahad AlTwaijiry -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Separate PHP Code From HTML || Pros Cons?
Hey all. I've built a simple, yet effective PHP based CMS, one that I use in all sites I develop. Unfortunately, from site-to-site, functionality may be different; i.e. I often have to extend the original CMS to account for custom client needs, which means grabbing the most recent version of my CMS, and hacking it to address whatever customization is required. This presents problems in that any updates I make to the CMS only affect the site I'm working on. So, while working on one site I may make changes to the CMS, changes that improve the app., but other older sites do not get updated -- it's OK now, but things are getting sloppy ;--) I would dearly love to have a base CMS repository that all sites would draw on, extending the base CMS in the event that a particular client has need of customization. Some combo of Linux and Apache would do the trick; e.g. PHP requests for any of my sites would point to say, /home/cms/includes/ That would help (not solve) the version control problems I'm running into now (still have to figure out how to extend the CMS for customization). Now, the other issue I'd like to address is separating PHP code logic from site HTML. I've restructured my CMS classes to do all MySQL queries, code logic, etc. prior to calling target HTML template. This is great in that now when an error occurs, I can catch { throw new Exception($e) } and gracefully display the error along with a means to repopulating the offending form page. I've often heard the mantra, separate code from HTML, but it seems ridiculous at times to include tiny HTML snippets that can easily be echoed out, or stored in a variable. Smarty goes to the extreme in separating code from HTML, but looking at their templating system, I wonder what's the point? Is it the end of the world if you've got a few choice if, then, else statements in your HTML templates? I'm thinking of creating a bunch of include files based on request type in my CMS Admin Center; e.g. include classes/admin/news/add.php, where add, update, or delete is the request type. This cleans up my PHP processing pages quite a bit (don't have all the if add, do X, elseif update, do Y, etc. logic to comb through). Last thing to do is write up a generic form builder class to assemble my form pages, but that may be more work than necessary -- K-rist, webwork is messy business ;--) Clues, Opinions, etc. are welcome. TIA, --Noah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] FTP
Hi, When I send files via FTP, the file size is limited to the php.ini max upload value? Thank you!
Re: [PHP] Re: Separate PHP Code From HTML || Pros Cons
On 10/7/06, sit1way [EMAIL PROTECTED] wrote: Hey all. This presents problems in that any updates I make to the CMS only affect the site I'm working on. So, while working on one site I may make changes to the CMS, changes that improve the app., but other older sites do not get updated -- it's OK now, but things are getting sloppy ;--) I would dearly love to have a base CMS repository that all sites would draw on, extending the base CMS in the event that a particular client has need of customization. Some combo of Linux and Apache would do the trick; e.g. PHP requests for any of my sites would point to say, /home/cms/includes/ Are you using a version control system? Using one and, maybe, reviewing your architeture for code re-use might help in this matter, I think Now, the other issue I'd like to address is separating PHP code logic from site HTML. (...) I've often heard the mantra, separate code from HTML, but it seems ridiculous at times to include tiny HTML snippets that can easily be echoed out, or stored in a variable. Smarty goes to the extreme in separating code from HTML, but looking at their templating system, I wonder what's the point? Is it the end of the world if you've got a few choice if, then, else statements in your HTML templates? Is of my understading that this mantra is about intention in the code. We have a framework written in PHP that also uses PHP as template language. I mean, we have source files that define components, where we use PHP to process the data normally (declaring classes, using DB, etc), but there are also snippet files were we have HTML + PHP. The special case here is that the snippet files have a couple of arrays with data (created and offered by the components) available and their only occupation is to process output: no DB access, no class declaration, no file inclusion, no socket connectionall they have to do is render HTML (or whatever) with the data they received. The most complex things we have in snippet files are small functions where recursions help displaying some widgets. Everything else are loops, decision strucutres and lots of print/echo. Simple source files, in the end. Thiago Silva
Re: [PHP] FTP
Hi Martins, Of course. You can alter it you want. I remember that file size limit devided into two type: 1) local access 2) remote access file size limit only limit remote access because I can upload file from local more than limit. Good luck!! Brad On 10/8/06, Raphael Martins [EMAIL PROTECTED] wrote: Hi, When I send files via FTP, the file size is limited to the php.ini max upload value? Thank you!
Re: [PHP] Re: Separate PHP Code From HTML || Pros Cons
I dont think its so bad. What I do is keep the PHP and HTML seperate, but in the same file: php on top, html in a here document at the bottom. I COULD go one step farther and have the HTML in a seperate file, but I just dont see the point. td On 10/7/06, Thiago Silva [EMAIL PROTECTED] wrote: On 10/7/06, sit1way [EMAIL PROTECTED] wrote: Hey all. This presents problems in that any updates I make to the CMS only affect the site I'm working on. So, while working on one site I may make changes to the CMS, changes that improve the app., but other older sites do not get updated -- it's OK now, but things are getting sloppy ;--) I would dearly love to have a base CMS repository that all sites would draw on, extending the base CMS in the event that a particular client has need of customization. Some combo of Linux and Apache would do the trick; e.g. PHP requests for any of my sites would point to say, /home/cms/includes/ Are you using a version control system? Using one and, maybe, reviewing your architeture for code re-use might help in this matter, I think Now, the other issue I'd like to address is separating PHP code logic from site HTML. (...) I've often heard the mantra, separate code from HTML, but it seems ridiculous at times to include tiny HTML snippets that can easily be echoed out, or stored in a variable. Smarty goes to the extreme in separating code from HTML, but looking at their templating system, I wonder what's the point? Is it the end of the world if you've got a few choice if, then, else statements in your HTML templates? Is of my understading that this mantra is about intention in the code. We have a framework written in PHP that also uses PHP as template language. I mean, we have source files that define components, where we use PHP to process the data normally (declaring classes, using DB, etc), but there are also snippet files were we have HTML + PHP. The special case here is that the snippet files have a couple of arrays with data (created and offered by the components) available and their only occupation is to process output: no DB access, no class declaration, no file inclusion, no socket connectionall they have to do is render HTML (or whatever) with the data they received. The most complex things we have in snippet files are small functions where recursions help displaying some widgets. Everything else are loops, decision strucutres and lots of print/echo. Simple source files, in the end. Thiago Silva -- Publish technical articles @ skilledwords.com and get 100% of the ad-revenue! http://www.skilledwords.com
[PHP] Re: set cookie with non-english
On Tue, 3 Oct 2006 01:15:59 +0300, Ahmad Al-Twaijiry wrote: Hi everyone in my PHP code I use the following command to set a cookie with non-english word (UTF-8) : @setcookie (UserName,$Check[1]); and in my html page I get this cookie using javascript : [Snipped] but the result from writing the cookie using javascript is garbage, I don't get the right word !! The problem is that JavaScript uses UTF-16, so you either have to store the cookie as UTF-16 or do your own UTF-8 decoding in JavaScript. For example, consider the string åäö, containing the three funny characters in the Swedish language (aring;auml;ouml;). These characters are encoded as c3 a5 c3 a4 c3 b6 in UTF-8, and PHP stores these in the cookie as: %C3%A5%C3%A4%C3%B6 Example: -- ?php setcookie ('UserName', \xc3\xa5\xc3\xa4\xc3\xb6); // setcookie ('UserName', åäö); header ('Content-Type: text/html; charset=utf-8'); ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; titleUTF-8 flavoured cookies/title p script type=text/javascript document.write(document.cookie); /script -- The unescape() function in JavaScript converts these characters to the Unicode code points 00c3 00a5 00c3 00a4 00c3 00b6 which, of course, is not what you want. Example: -- ?php setcookie ('UserName', \xc3\xa5\xc3\xa4\xc3\xb6); // setcookie ('UserName', åäö); header ('Content-Type: text/html; charset=utf-8'); ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; titleUTF-8 flavoured cookies/title p script type=text/javascript var s = unescape(document.cookie); var t = ; for (var i = 0; i s.length; i++) { var c = s.charCodeAt(i); t += c 128 ? String.fromCharCode(c) : c.toString(16) + ; } document.write(t); /script -- While there are no doubt better ways to solve this, you /could/ use the unescape() function to convert the percent-encoded characters to unicode code point, and then write your own UTF-8 decoder to do the rest. Example: (This is an old C function hammered into JavaScript shape. It is likely to be a horrible implementation in JavaScript. The error checking adds a bit of bloat. Note that the utf_8_decode function supports the full Unicode range, while JavaScript doesn't. ) -- ?php setcookie ('UserName', \xc3\xa5\xc3\xa4\xc3\xb6); header ('Content-Type: text/html; charset=utf-8'); ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; titleUTF-8 flavoured cookies/title p script type=text/javascript function utf_8_decode (sin) { function octet_count (c) { var octet_counts = [ /* c0 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* d0 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* e0 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* f0 */ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0 ]; return c 128 ? 1 : c 192 ? 0 : octet_counts [(c255)-192]; } var octet0_masks = [ 0x00,0x7f,0x1f,0x0f,0x07,0x03,0x01 ]; var sout = ; var add; for (var si = 0; si sin.length; si += add) { var c = sin.charCodeAt(si); add = octet_count(c); if (si+add = sin.length) { var u = c octet0_masks[add]; var ci; for (ci = 1; (ci add) ((sin.charCodeAt(si+ci)0xc0) == 0x80); ci++) u = (u6) | (sin.charCodeAt(si+ci) 0x3f); if (ci == add) { sout += String.fromCharCode (u); } else { // Invalid UTF-8 sequence. Should probably throw() instead. sout += \ufffd; // Replacement character. add = 1; } } else { // Invalid UTF-8 sequence. Should probably throw() instead. sout += \ufffd; // Replacement character. add = 1; } } return sout; } document.write (utf_8_decode(unescape(document.cookie))); /script -- BTW: * I also tried the php function setrawcookie and I get the same problem * I use META http-equiv=Content-Type content=text/html; charset=utf-8 in my page The META thing might be good for storing pages on disk, but on the web you should use real HTTP headers. --nfe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php