Re: [PHP] How to assign eval() to variable?
short hack, assuming your eval echo's out to the browser (which I can't see how else you'd expect something to 'return' from an eval'd statement ob_start(); eval($foo); $result = ob_get_clean(); On May 23, 2009 1:46am, Afan Pasalic a...@afan.net wrote: hi, I have on one website boxes with information, pulled from mysql. the content can be string, php code, url of other website or url to specific file etc. currently, I have something like this: // connect to db // mysql_query() to get box content and content_type switch($content_type) { case 'string': echo $content; break; case 'php_code': eval($content); break; case 'website': echo ''.$content.'; break; case 'file' require_once($file); echo $file_content; // etc. } but, now I have to change the code to assign content to variable and the variable will be printed later. I tried something like this: switch($content_type) { case 'string': $record = $content; break; case 'php_code': $record = eval($content); break; case 'website': $record = ''.$content.'; break; case 'file' require_once($file); $record = $file_content; // etc. } and it works - except eval() part. cant do $record = eval($content); ?!?!?!? thanks afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to assign eval() to variable?
short hack works like a charm! :-) thanks! afan oorza...@gmail.com wrote: short hack, assuming your eval echo's out to the browser (which I can't see how else you'd expect something to 'return' from an eval'd statement ob_start(); eval($foo); $result = ob_get_clean(); On May 23, 2009 1:46am, Afan Pasalic a...@afan.net wrote: hi, I have on one website boxes with information, pulled from mysql. the content can be string, php code, url of other website or url to specific file etc. currently, I have something like this: // connect to db // mysql_query() to get box content and content_type switch($content_type) { case 'string': echo $content; break; case 'php_code': eval($content); break; case 'website': echo ''.$content.'; break; case 'file' require_once($file); echo $file_content; // etc. } but, now I have to change the code to assign content to variable and the variable will be printed later. I tried something like this: switch($content_type) { case 'string': $record = $content; break; case 'php_code': $record = eval($content); break; case 'website': $record = ''.$content.'; break; case 'file' require_once($file); $record = $file_content; // etc. } and it works - except eval() part. cant do $record = eval($content); ?!?!?!? thanks afan -- 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] fgets function for very large files
hi all, I have a csv file with more than 100,000 lines. I want to insert each line as a record in a database. but for the reason of very number of lines, I put a button with caption Next, when we click on it, 1000 line will insert into db and then again click next button and insert next 1000 line and is this good way? what do you recommend? and how can I do that? Thanks in advance, shahrzad
Re: [PHP] fgets function for very large files
one thing! I need four fields of 7 fields in each line, in my code from original csv file first four of fields choose(mappping these fields with columns of table in db) for example: a line in csv file: a,b,c,d,e,f,g in table of database 4 column : name,ext,tel,date that 4 field of csv file must map to these column then I can't directly import my csv file into db. some process must do to insert just my selected fields of csv file... Thanks, Shahrzad
Re: [PHP] fgets function for very large files
shahrzad khorrami wrote: one thing! I need four fields of 7 fields in each line, in my code from original csv file first four of fields choose(mappping these fields with columns of table in db) for example: a line in csv file: a,b,c,d,e,f,g in table of database 4 column : name,ext,tel,date that 4 field of csv file must map to these column then I can't directly import my csv file into db. some process must do to insert just my selected fields of csv file... use awk to read the file and create a .sql file with the specified fields you want. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fgets function for very large files
On Sat, 2009-05-23 at 02:59 -0400, Eddie Drapkin wrote: On Sat, May 23, 2009 at 2:58 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: If it's a CSV, I'd recommend using phpMyAdmin directly to import it into the database, assuming you are using a MySQL database that is. It's using tried and tested code for large files like that. Tried and true to be what, exactly? Full of security holes and exploits and promoting bad habits? Really, if all you need to do for the database is import hte .csv, import it directly into mysql, from mysql: http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/ And on a related note, you should never, ever use PMA on a production machine as it's so easy to exploit and hack. Furthermore, if you use it on your dev server, you'll get used to managing your database with it and have trouble using it on the production server. Take the time to use a real DB administration app (like SQLyog of the one that comes with KDE) or an IDE with integrated SQL management (like PDT or Zend Studio or Aptana I think too). Bottom line is if you said you used PMA in an interview I had any say in, I'd never hire you and I'd never work with a developer who was that uncomfortable with SQL. I guess I don't get the job then! :p Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fgets function for very large files
i accept the fact that PMA is full of security holes, and it should not be used on production server. but it does not mean that we can never use it on a development server probably you may have a bit of trouble while moving from development server to production server. but u can always export your database to an .sql file and import it into production server... but if u dont have access to mysql command line(which is the case in nearly all of the projects i worked on), PMA will probably be the only option...(unless u want to rewrite the entire PMA code.) and certainly http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/ is best option for file with 5000 lines..(but you may hav to prefer PMA if mysql is not in your PATH env var) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Example PHP shared memory code
Hi I was wondering if anyone has some sample code whereby the PHP script connects to and reads data from some shared memory in Linux, where the shared memory was originally created by a* linux thread (as opposed to some PHP script)*? The example code needs to use shmop_open(...). Thanks in advance. Cheers, Richard
Re: [PHP] How to assign eval() to variable?
2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Suggestions... oorza...@gmail.com wrote: short hack, assuming your eval echo's out to the browser (which I can't see how else you'd expect something to 'return' from an eval'd statement ob_start(); eval($foo); $result = ob_get_clean(); On May 23, 2009 1:46am, Afan Pasalic a...@afan.net wrote: hi, I have on one website boxes with information, pulled from mysql. the content can be string, php code, url of other website or url to specific file etc. currently, I have something like this: // connect to db // mysql_query() to get box content and content_type switch($content_type) { case 'string': echo $content; break; case 'php_code': eval($content); break; case 'website': echo ''.$content.'; break; case 'file' require_once($file); echo $file_content; // etc. } but, now I have to change the code to assign content to variable and the variable will be printed later. I tried something like this: switch($content_type) { case 'string': $record = $content; break; case 'php_code': $record = eval($content); break; case 'website': $record = ''.$content.'; break; case 'file' require_once($file); $record = $file_content; // etc. } and it works - except eval() part. cant do $record = eval($content); ?!?!?!? thanks afan -- 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] How to assign eval() to variable?
Oops, didn't mean to hit send... 2009/5/23 Stuart stut...@gmail.com: 2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Suggestions... 1) RTFM: http://uk.php.net/eval 2) If you can avoid using eval, do. It's evil and rarely the best way to achieve something. -Stuart -- http://stut.net/ oorza...@gmail.com wrote: short hack, assuming your eval echo's out to the browser (which I can't see how else you'd expect something to 'return' from an eval'd statement ob_start(); eval($foo); $result = ob_get_clean(); On May 23, 2009 1:46am, Afan Pasalic a...@afan.net wrote: hi, I have on one website boxes with information, pulled from mysql. the content can be string, php code, url of other website or url to specific file etc. currently, I have something like this: // connect to db // mysql_query() to get box content and content_type switch($content_type) { case 'string': echo $content; break; case 'php_code': eval($content); break; case 'website': echo ''.$content.'; break; case 'file' require_once($file); echo $file_content; // etc. } but, now I have to change the code to assign content to variable and the variable will be printed later. I tried something like this: switch($content_type) { case 'string': $record = $content; break; case 'php_code': $record = eval($content); break; case 'website': $record = ''.$content.'; break; case 'file' require_once($file); $record = $file_content; // etc. } and it works - except eval() part. cant do $record = eval($content); ?!?!?!? thanks afan -- 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] How to create an intermediary page between two pages
At 2:20 PM +0200 5/23/09, Moses wrote: Hi Folks, I would like to know whether you can connect two pages via an intermediary page. For example if you have main.php, which is a form whose action is directed to function.php. Function.php process the information from main.php then displays the result. This can take roughly 6 seconds or more. Is it possible to create an intermediary page which alerts the user that the his/her request is being processed in few seconds, then ultimately redirects to function.php (display results). Any idea shall be appreciated. Thanks. Moses Moses: Two things: 1. Anytime the user has to wait, provide a notice of what's happening, such as wait gif to let them know something is happening. Here are some examples: http://webbytedd.com/bb/wait/ 2. Why two scripts? Why not just create a single script? I often have a single script that simply submits forms to itself and evaluates the contents. If the contents pass inspection, then the script moves on to the next step. If not, then the script shows the user where the problem is and ask for the user to fill the form out correctly. I often couple this with javascript to provide more immediate interaction with the user, such as checking proper email format, password and password-confirmation being equal, input required fields, and other client-side stuff. This helps with preparing the data before submission. But I ultimately check and validate all incoming data server-side before doing anything important with it. There's no rule that says everything must be done in separate pages/scripts. Consider this, use a $step variable and set the initial value to 0. Drop the user into the first form and use a input type='hidden' name='step' value='1' within that form. When the user clicks submit, then $step = $_POST['step'] will equal 1 and process the data submitted via a switch or if statement. If everything is Okay, then continue to the next part. If not, then set $step=0 and start over again. Some of my forms have up to ten steps and that's the way I do it. Cheers, 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
Re: [PHP] Re: table-less layouts; Ideas welcome
Have anyone of you checked the table to div converter class from www.phpclasses.org ?
Re: [PHP] How to assign eval() to variable?
On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: 2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Where di you hear that output buffers are expensive? I have found the following: ?php ob_start(); for( $i = 0; $i 1000; $i++ ) { echo 'blaah'; } $foo = ob_get_contents(); ob_end_clean(); ? To consistently be faster than the following: ?php for( $i = 0; $i 1000; $i++ ) { $foo .= 'blaah'; } ? However, if I do the following: ?php for( $i = 0; $i 1000; $i++ ) { ob_start(); echo 'blaah'; $foo .= ob_get_contents(); ob_end_clean(); } ? The run-time is approximately 3 times slower... not exactly expensive considering it incorporates the concatenation as well as the output buffering. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to assign eval() to variable?
2009/5/23 Robert Cummings rob...@interjinn.com: On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: 2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Where di you hear that output buffers are expensive? I have found the following: ?php ob_start(); for( $i = 0; $i 1000; $i++ ) { echo 'blaah'; } $foo = ob_get_contents(); ob_end_clean(); ? To consistently be faster than the following: ?php for( $i = 0; $i 1000; $i++ ) { $foo .= 'blaah'; } ? However, if I do the following: ?php for( $i = 0; $i 1000; $i++ ) { ob_start(); echo 'blaah'; $foo .= ob_get_contents(); ob_end_clean(); } ? The run-time is approximately 3 times slower... not exactly expensive considering it incorporates the concatenation as well as the output buffering. Context is everything Rob. I said *relatively* expensive because the comparison was between using an output buffer to capture a value from a call to eval compared to simply returning the value from the eval'd code. Context. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to assign eval() to variable?
On Sat, 2009-05-23 at 15:11 +0100, Stuart wrote: 2009/5/23 Robert Cummings rob...@interjinn.com: On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: 2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Where di you hear that output buffers are expensive? I have found the following: ?php ob_start(); for( $i = 0; $i 1000; $i++ ) { echo 'blaah'; } $foo = ob_get_contents(); ob_end_clean(); ? To consistently be faster than the following: ?php for( $i = 0; $i 1000; $i++ ) { $foo .= 'blaah'; } ? However, if I do the following: ?php for( $i = 0; $i 1000; $i++ ) { ob_start(); echo 'blaah'; $foo .= ob_get_contents(); ob_end_clean(); } ? The run-time is approximately 3 times slower... not exactly expensive considering it incorporates the concatenation as well as the output buffering. Context is everything Rob. I said *relatively* expensive because the comparison was between using an output buffer to capture a value from a call to eval compared to simply returning the value from the eval'd code. You should have connected your phrasing to context then. Your wording suggested a generalization. Relatively expensive did not relate to any other information you provided in the same sentence... relatively expensive to what? It was in the first sentence, before you introduced information about returning directly from the eval statement. Information linkage is important, as is chronology. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Legal $_SESSION names
At 2:25 PM +0100 5/23/09, Stuart wrote: 2009/5/22 tedd t...@sperling.com: Regardless of what anyone may say to the contrary, it doesn't work everywhere. I found that out the hard way. The fix is simply to use a different name for the variable, such as: $my_var = $_SESSION['myvar']; I'm just guessing but I'd say this has to do with the way superglobals are created. Since 5.0.0 a configuration option called auto_globals_jit has existed and it defaults to being on. It causes the creation of superglobals to be delayed until they are actually used. I don't know how it interacts with register_globals (the manual says it'll be disabled if register_globals is on) but it makes sense to me that this issue is related to that. I'd say you've found a bug, but you'll need a repeatable example before you can report it. -Stuart -Stuart: I'm pretty sure it's a bug -- all of my scripts work and one doesn't within the same environment. I have a routine where an Administrator can bypass the logon procedures of a registered user to the site and see what the user sees. To do that I simply use a bypass session variable namely: $bypass = $_SESSION['bypass']; I use this exact same statement in 13 different scripts and it works. However, in one script, I have to change the statement to: $by_pass = $_SESSION['bypass']; to make it work. Otherwise it fails with some vague error code about using something that has been depreciated. Considering that the error is surrounded by so much code, I don't want to wade through it all and find the exact problem and report it. Instead, I'm just saying if someone runs into this problem like this, they might try changing the variable name. It's a simple fix, but it's hard to identify. Cheers, 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
Re: [PHP] How to assign eval() to variable?
2009/5/23 Robert Cummings rob...@interjinn.com: On Sat, 2009-05-23 at 15:11 +0100, Stuart wrote: 2009/5/23 Robert Cummings rob...@interjinn.com: On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: 2009/5/23 Afan Pasalic a...@afan.net: short hack works like a charm! :-) It may work but output buffers are relatively expensive. The eval function will return the value the eval'd code returns, so just stick a return statement at the end of the string you're eval'ing. Where di you hear that output buffers are expensive? I have found the following: ?php ob_start(); for( $i = 0; $i 1000; $i++ ) { echo 'blaah'; } $foo = ob_get_contents(); ob_end_clean(); ? To consistently be faster than the following: ?php for( $i = 0; $i 1000; $i++ ) { $foo .= 'blaah'; } ? However, if I do the following: ?php for( $i = 0; $i 1000; $i++ ) { ob_start(); echo 'blaah'; $foo .= ob_get_contents(); ob_end_clean(); } ? The run-time is approximately 3 times slower... not exactly expensive considering it incorporates the concatenation as well as the output buffering. Context is everything Rob. I said *relatively* expensive because the comparison was between using an output buffer to capture a value from a call to eval compared to simply returning the value from the eval'd code. You should have connected your phrasing to context then. Your wording suggested a generalization. Relatively expensive did not relate to any other information you provided in the same sentence... relatively expensive to what? It was in the first sentence, before you introduced information about returning directly from the eval statement. Information linkage is important, as is chronology. Looking back at what I wrote I agree that I could have made it clearer. The context I was relying on from the message I was replying to did not adequately frame my comment. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to create an intermediary page between two pages
Dear Folks, Thanks Tedd for the reply. Do you have a simple example to ilustrate your great idea. Thanks. On Sat, May 23, 2009 at 3:47 PM, tedd tedd.sperl...@gmail.com wrote: At 2:20 PM +0200 5/23/09, Moses wrote: Hi Folks, I would like to know whether you can connect two pages via an intermediary page. For example if you have main.php, which is a form whose action is directed to function.php. Function.php process the information from main.php then displays the result. This can take roughly 6 seconds or more. Is it possible to create an intermediary page which alerts the user that the his/her request is being processed in few seconds, then ultimately redirects to function.php (display results). Any idea shall be appreciated. Thanks. Moses Moses: Two things: 1. Anytime the user has to wait, provide a notice of what's happening, such as wait gif to let them know something is happening. Here are some examples: http://webbytedd.com/bb/wait/ 2. Why two scripts? Why not just create a single script? I often have a single script that simply submits forms to itself and evaluates the contents. If the contents pass inspection, then the script moves on to the next step. If not, then the script shows the user where the problem is and ask for the user to fill the form out correctly. I often couple this with javascript to provide more immediate interaction with the user, such as checking proper email format, password and password-confirmation being equal, input required fields, and other client-side stuff. This helps with preparing the data before submission. But I ultimately check and validate all incoming data server-side before doing anything important with it. There's no rule that says everything must be done in separate pages/scripts. Consider this, use a $step variable and set the initial value to 0. Drop the user into the first form and use a input type='hidden' name='step' value='1' within that form. When the user clicks submit, then $step = $_POST['step'] will equal 1 and process the data submitted via a switch or if statement. If everything is Okay, then continue to the next part. If not, then set $step=0 and start over again. Some of my forms have up to ten steps and that's the way I do it. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com
Re: [PHP] Re: table-less layouts; Ideas welcome
At 9:08 AM -0400 5/23/09, Robert Cummings wrote: Ya know... the people over at HTML standards design cold have saved the world a large number of headaches by just adding a new attribute to tables: table type=layout Then everyone layout table out there would have been valid by the simple addition of this attribue, backward compatible with older browsers, understandable by future screen readers, and much less hassle in general. But, I guess they were lacking some insight there. Instead we got a CSS spec to support table layouts that depended on the asshats over at Microsoft adding support, required all browsers at the time be upgraded, and today is pretty much useless in a global perspective. I'm all for standards, we could have even overlapped this system with CSS support so that when the browser support ultimately came, the switch would be simple. But no, simplicity would have been far too easy for everyone to swallow. Rob: Ain't that the truth. On one side, people who had very little programming skills took advantage of the HTML language through WYSIWYG editors and created something that solved their needs. On the other side, the same people who didn't foresee the problem when they created the language ignores the obvious need for layout and then further complicates the issue by redefining tables and requiring a css solution. They could have easily sought a simple solution such as what you suggested. I often think there should be a grid of some sort to allow people to construct a layout without having to consider the more problematic css positioning and float rules. What better solves that layout problem than a table? Opportunities lost. Ps. sorry for disappearing from this thread, I had a funeral to attend and had no internet for a week... yes I'm still shaking from withdrawal ;) Sorry about the funeral -- I hope there was nothing seriously wrong. :-) Cheers, 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
Re: [PHP] How to assign eval() to variable?
At 3:34 PM +0100 5/23/09, Stuart wrote: 2009/5/23 Robert Cummings rob...@interjinn.com: You should have connected your phrasing to context then. Your wording suggested a generalization. Relatively expensive did not relate to any other information you provided in the same sentence... relatively expensive to what? It was in the first sentence, before you introduced information about returning directly from the eval statement. Information linkage is important, as is chronology. Looking back at what I wrote I agree that I could have made it clearer. The context I was relying on from the message I was replying to did not adequately frame my comment. And don't let it happen again. :-) Without Rob pointing it out I would have never noticed. Cheers, 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
Re: [PHP] How to create an intermediary page between two pages
At 4:34 PM +0200 5/23/09, Moses wrote: Dear Folks, Thanks Tedd for the reply. Do you have a simple example to ilustrate your great idea. Thanks. Moses: It's not a great idea, just a simple solution to a common problem -- see here: http://www.webbytedd.com/b3/step-example/ Cheers, 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] how to delete part of string
I have a POST string field and I want to skip some fields before id= How do I simply delete operation=nekajprice=fddfid=deid=ta ... into id=deid=ta ... Thanks in advance, -- When the sun rises I receive and when it sets I forgive - http://users.skavt.net/~gleskovs/ All the Love, Grega Leskov'sek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to delete part of string
I guess you mean GET parameters instead of POST. $string = preg_replace('/^(.*?)id=/', 'id=', $_SERVER['QUERY_STRING']); Don't know, if that's exactly what you wanted. Greetings from Germany Marc Grega Leskovsek wrote: I have a POST string field and I want to skip some fields before id= How do I simply delete operation=nekajprice=fddfid=deid=ta ... into id=deid=ta ... Thanks in advance, -- Synchronize and share your files over the web for free http://bithub.net/ My Twitter feed http://twitter.com/MarcSteinert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Forms validation and creation- easier solution?
Daniele Grillenzoni dani...@b2informatica.it wrote in message news:16.1e.28112.84ca5...@pb1.pair.com... On 20/05/2009 9.03, Angelo Zanetti wrote: Hi all. We have done quite a few projects and we are looking to find better ways to implementing forms. Forms seem to be quite time consuming and repetitive. Generally are there any classes or libraries that will assist with: 1. Easy creation of forms (fields and layout) 2. Validation of specific fields within the forms (server side not JS) 3. Decrease in time required to setup the forms pages any other comments are welcome. Thanks in advance Angelo Elemental http://www.elemental.co.zahttp://www.elemental.co.za/ Dynamic Web and Mobile Solutions Personally I created a little Class that handles it. First I create an array of associative arrays, every associative array represents an input of an abstract type (similar to the webforms, meaning i have stuff like type=telephone). Stuff like $inputs[]=array( name = foobar, required = true, type = string, // text is reserved to textarea label = Foo Bar, error_required = you need to provide a Foo Bar value, dummy, group = main ); etc. Then I create an array for groups. $group[main] = array( type = block, // types are either block which means div, set which means fieldset, paragraph which means p or a raw html opening tag. parent = NULL //optional of course, if set to the name of another group, then the group becomes a child of the referenced group. ) Then I create an associative array of options for the form. Finally, I call the class constructor with the three arrays as params. The class provides me with a few nifty functions: * toHtml(); (do I need to explain?) * toArray(); Returns the inputs, options, and groups inside a single array, with the value altered when necessary * wasSubmitted(); Does some guesswork to see if the form was submitted, there's a lot of smart automagicness inside. * runAutoChecks(); Runs the checks he can, like the validity of emails in 'type' = 'email' inputs, pattern validation for input with a set pattern, required inputs, fills the error array with error messages, sets class[]='error' to wrongly filled inputs... * wasValidInput(); Returns true if none of the autochecks or eventual manual checks returned an error. And it works like this: [...] if ($form-wasSubmitted()){ $form-runAutoChecks(); /* Additional non-automatable controls */ // None in this case if ($form-wasValidInput()){ // success, do stuff } else { // show errors and form again } } else { echo $form-toHtml(); } There are other things I didn't list, like the fact that ever input has options to specify a wrapper (class and id are associated to the wrapper if it's defined), the form encoding automatically changes in case of a file input, etc etc etc... The types are abstracted enough that one could easily make a function that automatically creates the code for a first draft of the forum out of the db schema of an eventual table. Of course you'd have to provide error messages, remove unnecessary inputs, adding new ones... Your ideas are similar to mine, but I have a much more advanced implementation which involves the use of a Data Dictionary. After building a database table I import the structure into my data dictionary, then export it to create a database table class and a table structure file. Still using the data dictionary I can then build the family of transactions to maintain that database table. This uses a standard set of page controllers and XSL templates to build the HTML. So within 5 minutes I can run the transactions to list, search, add, enquire, delete and update that database table without having to write a single line of SQL or HTML. In most cases I don't even have to write a single line of PHP. Is your method as fast as that? All this functionality exists within the Radicore framework, so you can download it and try it for yourself. -- Tony Marston http://www.tonymarston.net http://www.radicore.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to delete part of string
No, I used POST and manage the data through a stream: if ($fp = fopen(php://input, 'r')) { $content = ''; // keep reading until there's nothing left while ($line = fgets($fp)) { $content .= $line; } } Please advice on the matter. All the Love, Grega from Slovenia 2009/5/23 Marc Steinert li...@bithub.net: I guess you mean GET parameters instead of POST. $string = preg_replace('/^(.*?)id=/', 'id=', $_SERVER['QUERY_STRING']); Don't know, if that's exactly what you wanted. Greetings from Germany Marc Grega Leskovsek wrote: I have a POST string field and I want to skip some fields before id= How do I simply delete operation=nekajprice=fddfid=deid=ta ... into id=deid=ta ... Thanks in advance, -- Synchronize and share your files over the web for free http://bithub.net/ My Twitter feed http://twitter.com/MarcSteinert -- When the sun rises I receive and when it sets I forgive - http://users.skavt.net/~gleskovs/ All the Love, Grega Leskov'sek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Forms validation and creation- easier solution?
Tony Marston wrote: Your ideas are similar to mine, but I have a much more advanced implementation which involves the use of a Data Dictionary. After building a database table I import the structure into my data dictionary, then export it to create a database table class and a table structure file. Still using the data dictionary I can then build the family of transactions to maintain that database table. This uses a standard set of page controllers and XSL templates to build the HTML. So within 5 minutes I can run the transactions to list, search, add, enquire, delete and update that database table without having to write a single line of SQL or HTML. In most cases I don't even have to write a single line of PHP. Is your method as fast as that? All this functionality exists within the Radicore framework, so you can download it and try it for yourself. Thank you! I am moving out of do it hand to learn how it is done into how can I get this work done quickly and well and you point me to Radicore! Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to delete part of string
What are you trying to do that $_POST can't do? With those duplicate 'id' fields, change the input name to 'id[]' in the HTML form and PHP will generate an array for you accessible by $_POST['id'][$index]. If you still have a good reason for working with the raw POST data, just apply the preg_replace code Marc gave to the content you retrieve from php://input. On Sat, May 23, 2009 at 11:41 AM, Grega Leskovsek mavri...@gmail.com wrote: No, I used POST and manage the data through a stream: if ($fp = fopen(php://input, 'r')) { $content = ''; // keep reading until there's nothing left while ($line = fgets($fp)) { $content .= $line; } } Please advice on the matter. All the Love, Grega from Slovenia 2009/5/23 Marc Steinert li...@bithub.net: I guess you mean GET parameters instead of POST. $string = preg_replace('/^(.*?)id=/', 'id=', $_SERVER['QUERY_STRING']); Don't know, if that's exactly what you wanted. Greetings from Germany Marc Grega Leskovsek wrote: I have a POST string field and I want to skip some fields before id= How do I simply delete operation=nekajprice=fddfid=deid=ta ... into id=deid=ta ... Thanks in advance, -- Synchronize and share your files over the web for free http://bithub.net/ My Twitter feed http://twitter.com/MarcSteinert -- When the sun rises I receive and when it sets I forgive - http://users.skavt.net/~gleskovs/ All the Love, Grega Leskov'sek -- 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: Rogue 'if - elseif' code
On Fri, May 22, 2009 at 2:50 PM, Nathan Rixham nrix...@gmail.com wrote: Andre Dubuc wrote: Hi, I'm having problems with a chunk of 'rogue' code that does not perform as expected (it does not pass the expected date, but an empty value). Most of the time, it works - so I'm wondering whether it might be a browser issue. (The latest failure occurred with Firfeox 3.0 browser on an NT 5.1 OS.) The code is stored on an Unix server, running PHP 5.x. I've isolated it down to multiple if - elseif statements that check long dates for completeness, day month and year. The code then applies it results printing one of following: the full date - 22 May 2009, month-year - May 2009, or just the year, 2009. My question is whether the ORDER of checking is important, i.e, whether checking for the null sets BEFORE full sets or AFTER. I've added debugging code to be able to get the raw POST values so I can manually enter it into the db, but I would really appreciate some help here. The code is old -- I wrote it seven years ago, and had worked well until I modified it, but I no longer have the original working code. [The first conditional line of the code checks whether the user has entered the birth date, then it checks for the death date. The $_SESSION stuff is debugging code.] ?php $yd = $_POST['death']; $yb = $_POST['birth']; if ($_POST['bday'] == Day $_POST['bmonth'] == Month $_POST['birth'] == Year) { if ($_POST['dday'] != Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}); $_SESSION['ALL1rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] == Month $_POST['death'] != Year) { $_POST['rdod'] = $_POST['death']; $_SESSION['YEAR1rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dmonth']} {$_POST['death']}); $_SESSION['MONTHYEAR1rdod'] = $_POST['rdod']; } $_SESSION['Sdebugdod1'] = {$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}; } else { if ($yd $yb) { if ($_POST['bday'] != Day $_POST['bmonth'] != Month $_POST['birth'] != Year) { $_POST['rdob'] = ({$_POST['bday']} {$_POST['bmonth']} {$_POST['birth']}); } elseif ($_POST['bday'] == Day $_POST['bmonth'] == Month $_POST['birth'] != Year) { $_POST['rdob'] = $_POST['birth']; } elseif ($_POST['bday'] == Day $_POST['bmonth'] != Month $_POST['birth'] != Year) { $_POST['rdob'] = ({$_POST['bmonth']} {$_POST['birth']}); } if ($_POST['dday'] != Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}); $_SESSION['ALL2rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] == Month $_POST['death'] != Year) { $_POST['rdod'] = $_POST['death']; $_SESSION['YEAR2rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dmonth']} {$_POST['death']}); $_SESSION['MONTHYEAR2rdod'] = $_POST['rdod']; } $_SESSION['Sdebugdod2'] = {$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}; } ? Any help or pointers would be greatly appreciated! Tia, Andre makes no sense at all to me without some decent variable names rdod? - would also need the form to be honest, and a description of the functionality needed. one thing i can say is that you have a closing bracket missing at the end and your $_SESSION['Sdebugdod2'] appears to be in the wrong place (to solve both these try sticking a } before $_SESSION['Sdebugdod2'] really though, change the names in the form to something more descriptive -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yes, additional
Re: [PHP] Re: Rogue 'if - elseif' code
LinuxManMikeC wrote: On Fri, May 22, 2009 at 2:50 PM, Nathan Rixham nrix...@gmail.com wrote: Andre Dubuc wrote: Hi, I'm having problems with a chunk of 'rogue' code that does not perform as expected (it does not pass the expected date, but an empty value). Most of the time, it works - so I'm wondering whether it might be a browser issue. (The latest failure occurred with Firfeox 3.0 browser on an NT 5.1 OS.) The code is stored on an Unix server, running PHP 5.x. I've isolated it down to multiple if - elseif statements that check long dates for completeness, day month and year. The code then applies it results printing one of following: the full date - 22 May 2009, month-year - May 2009, or just the year, 2009. My question is whether the ORDER of checking is important, i.e, whether checking for the null sets BEFORE full sets or AFTER. I've added debugging code to be able to get the raw POST values so I can manually enter it into the db, but I would really appreciate some help here. The code is old -- I wrote it seven years ago, and had worked well until I modified it, but I no longer have the original working code. [The first conditional line of the code checks whether the user has entered the birth date, then it checks for the death date. The $_SESSION stuff is debugging code.] ?php $yd = $_POST['death']; $yb = $_POST['birth']; if ($_POST['bday'] == Day $_POST['bmonth'] == Month $_POST['birth'] == Year) { if ($_POST['dday'] != Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}); $_SESSION['ALL1rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] == Month $_POST['death'] != Year) { $_POST['rdod'] = $_POST['death']; $_SESSION['YEAR1rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dmonth']} {$_POST['death']}); $_SESSION['MONTHYEAR1rdod'] = $_POST['rdod']; } $_SESSION['Sdebugdod1'] = {$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}; } else { if ($yd $yb) { if ($_POST['bday'] != Day $_POST['bmonth'] != Month $_POST['birth'] != Year) { $_POST['rdob'] = ({$_POST['bday']} {$_POST['bmonth']} {$_POST['birth']}); } elseif ($_POST['bday'] == Day $_POST['bmonth'] == Month $_POST['birth'] != Year) { $_POST['rdob'] = $_POST['birth']; } elseif ($_POST['bday'] == Day $_POST['bmonth'] != Month $_POST['birth'] != Year) { $_POST['rdob'] = ({$_POST['bmonth']} {$_POST['birth']}); } if ($_POST['dday'] != Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}); $_SESSION['ALL2rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] == Month $_POST['death'] != Year) { $_POST['rdod'] = $_POST['death']; $_SESSION['YEAR2rdod'] = $_POST['rdod']; } elseif ($_POST['dday'] == Day $_POST['dmonth'] != Month $_POST['death'] != Year) { $_POST['rdod'] = ({$_POST['dmonth']} {$_POST['death']}); $_SESSION['MONTHYEAR2rdod'] = $_POST['rdod']; } $_SESSION['Sdebugdod2'] = {$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}; } ? Any help or pointers would be greatly appreciated! Tia, Andre makes no sense at all to me without some decent variable names rdod? - would also need the form to be honest, and a description of the functionality needed. one thing i can say is that you have a closing bracket missing at the end and your $_SESSION['Sdebugdod2'] appears to be in the wrong place (to solve both these try sticking a } before $_SESSION['Sdebugdod2'] really though, change the names in the form to something more descriptive -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yes, additional context would be great. Also, it looks like Andre is storing all his
Re: [PHP] urgent CSS question
Maybe there is another CSS rule that also matches the same context and overrides parts of the #frame1 rule, but didn't match when using the old #frame rule. Just my two cents. On Fri, May 22, 2009 at 7:15 PM, PJ af.gour...@videotron.ca wrote: Benjamin Hawkes-Lewis wrote: On 22/5/09 20:31, PJ wrote: They may have different names, but does that change their functionality? Potentially, yes! A selector including #frame will no longer match if id is changed to frame1, and vice versa. They are identical except for the 1 in the title of the id. So, if I change the one id to the other in the same code, I don't understand why the formatting would change? These descriptions are still far too vague and ambiguous. Please link to two test cases: 1) Effectively showing frame1. 2) Effectively showing frame. that illustrate the problem you're talking about. Obviously, the parents and the children have not changed unless there's some weird hanky-panky going on. Without seeing test cases, nothing is obvious. Or do I have to make a new css file for every page Only if you're doing it wrong. :) And to follow the logic here, if I create a different id and in the end it turns out to be identical to the original frame except for the name, shouldn't it function the same. That depends on: 1) The contents of your CSS file, which I can't see. 2) Whether you've made any errors when modifying your HTML, which I can't see either. If you provided test cases, I could see these things and answer your questions. Trying to describe the problem rather than /showing/ the problem is very inefficient. -- Benjamin Hawkes-Lewis Ok, I'm glad the there are some people out there who want to get down to the bottom of things. I can attach or maybe put up a link on a website where you can look at the code and the css. But regardless of any test caste, nothing changes the fact that whatever the html code, whatever the php code, these are sonstant and nothing is changed. Switch between id frame and id frame1 and things change. nothnig, I meant, nothing is changed in between. The difference is in the css, and nothing else. I'll post the location later tonight or , more likely, tomorrow am. z -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.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
[PHP] templating engine options
Hi All, Just a quick one, can anybody recommend any decent templating engines other than smarty. I've got no problem with smarty and it does the job - but if there is something newer and lighter out there that I'm missing then I'd be a fool not to at least consider it! can't be part of a framework, (or if it is easily extracted with no framework dependencies), and not xslt (love xslt, but not many designers do!). many regards, Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
On Sat, May 23, 2009 at 4:21 PM, Nathan Rixham nrix...@gmail.com wrote: Hi All, Just a quick one, can anybody recommend any decent templating engines other than smarty. I've got no problem with smarty and it does the job - but if there is something newer and lighter out there that I'm missing then I'd be a fool not to at least consider it! can't be part of a framework, (or if it is easily extracted with no framework dependencies), and not xslt (love xslt, but not many designers do!). many regards, Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I was recently researching template engines for a small in-house project, with a bias toward simple and lightweight. I found this interesting article in my search. I think its worth considering if you don't need all the bells and whistles of the big template engines. Simple and elegant. http://www.massassi.com/php/articles/template_engines/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
On Sat, 2009-05-23 at 23:21 +0100, Nathan Rixham wrote: Hi All, Just a quick one, can anybody recommend any decent templating engines other than smarty. I've got no problem with smarty and it does the job - but if there is something newer and lighter out there that I'm missing then I'd be a fool not to at least consider it! can't be part of a framework, (or if it is easily extracted with no framework dependencies), and not xslt (love xslt, but not many designers do!). eZ Components Use just the template component http://ezcomponents.org Kevin http://phpro.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
Kevin Waterson wrote: On Sat, 2009-05-23 at 23:21 +0100, Nathan Rixham wrote: Hi All, Just a quick one, can anybody recommend any decent templating engines other than smarty. I've got no problem with smarty and it does the job - but if there is something newer and lighter out there that I'm missing then I'd be a fool not to at least consider it! can't be part of a framework, (or if it is easily extracted with no framework dependencies), and not xslt (love xslt, but not many designers do!). eZ Components Use just the template component http://ezcomponents.org Kevin http://phpro.org cheers for that kevin, does look good; kind of smarty++ - will need to give it a try out! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: table-less layouts; Ideas welcome
Paul M Foster wrote: I wish someone had thought of a similar thing for databases. From the beginning, there should have been a spreadsheet-like interface for databases. This could have saved endless trouble, since for lack of this, people store database information in spreadsheets. And then wonder why they can't do this or that with it. Argh. If I'm not mistaken, Filemaker Pro on Apple was that way back in the OS 7.6 days. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php