php-general Digest 2 Nov 2009 08:53:33 -0000 Issue 6422
php-general Digest 2 Nov 2009 08:53:33 - Issue 6422 Topics (messages 299552 through 299557): Classes and Functions 299552 by: Daniel Kolbo 299553 by: Mathieu Rochette 299554 by: Larry Garfield shell_exec fails to compile java class? 299555 by: ×× ××× ×× ×× Re: Help with my first recursion menu 299556 by: Lex Braun PHP and Javascript escape character problem, -- those who like to solve things can try to solve this issue, its tricky I think ;) 299557 by: acetrader Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Hello, Is there a way to see what objects and functions a script loaded/required/used? I could recursively loop through the globals, but if objects were unset, then i may miss some. I could make a 'tracking' object and every time i load/include a file (which contains a class def or a function def) to add that file to the tracking object...but it would be nice if i didn't have to modify my existing code to see which objects and functions a script actually used, or at least, requested and loaded into memory. Thanks in advance, Daniel Kolbo ` ---End Message--- ---BeginMessage--- On Sun, Nov 1, 2009 at 9:50 PM, Daniel Kolbo kolb0...@umn.edu wrote: Hello, Is there a way to see what objects and functions a script loaded/required/used? I don't think it's possible to that in PHP code. I could recursively loop through the globals, but if objects were unset, then i may miss some. I could make a 'tracking' object and every time i load/include a file (which contains a class def or a function def) to add that file to the tracking object...but it would be nice if i didn't have to modify my existing code to see which objects and functions a script actually used, or at least, requested and loaded into memory. maybe what you are looking for is xdebug (http://xdebug.org/). It provide code coverage analysis. Thanks in advance, Daniel Kolbo ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? ---End Message--- ---BeginMessage--- On Sunday 01 November 2009 2:50:55 pm Daniel Kolbo wrote: Hello, Is there a way to see what objects and functions a script loaded/required/used? I could recursively loop through the globals, but if objects were unset, then i may miss some. I could make a 'tracking' object and every time i load/include a file (which contains a class def or a function def) to add that file to the tracking object...but it would be nice if i didn't have to modify my existing code to see which objects and functions a script actually used, or at least, requested and loaded into memory. Thanks in advance, Daniel Kolbo ` Depends what you are trying to do with it, but I suspect these are a good start: http://www.php.net/get_defined_functions http://www.php.net/get_defined_vars http://www.php.net/get_defined_constants http://www.php.net/get_declared_classes http://www.php.net/get_declared_interfaces http://www.php.net/get_included_files -- Larry Garfield la...@garfieldtech.com ---End Message--- ---BeginMessage--- Hello! I need to use shell_exec (or any other similar function) in order to compile a java class-file. I have all the needed components installed on my computer (Windows XP with Java SDK) - I can use java c:\path in order to compile using Start-Run. When I try to do the same with shell_exec or `` it returns null and it doesn't compiles. Even when there are errors - it doesn't show them at all. I've tried to use instead of java c:\path... the full java command line compiler path but it didn't work either. When I try functions such as echo test it works. Clearly I'm missing here something - problem is... what? -- Use ROT26 for best security ---End Message--- ---BeginMessage--- Hi, On Sat, Oct 31, 2009 at 11:07 AM, MEM tal...@gmail.com wrote: *From:* Lex Braun [mailto:lex.br...@gmail.com] *Sent:* sábado, 31 de Outubro de 2009 14:05 *To:* MEM *Cc:* php-gene...@lists.php.net *Subject:* Re: [PHP] RE: Help with my first recursion menu Hi, On Wed, Oct 28, 2009 at 5:22 PM, MEM tal...@gmail.com wrote: I've been told that stack is the way to go, so I'm trying to understand the following code: http://pastebin.com/m5616c88f I've commented every line so that any of you could see if I'm interpreting something wrong: I have two questions about this code, that hopefully someone on the list could explain: 1) Why do we need to remove the last array item? (on line 32): array_pop($urlStack); On line 20,
php-general Digest 2 Nov 2009 23:24:53 -0000 Issue 6423
php-general Digest 2 Nov 2009 23:24:53 - Issue 6423 Topics (messages 299558 through 299576): Re: Help with my first recursion menu 299558 by: MEM Re: PHP and Javascript escape character problem, -- those who like to solve things can try to solve this issue, its tricky I think ;) 299559 by: Devendra Jadhav 299561 by: Ashley Sheridan 299562 by: Stuart 299563 by: Devendra Jadhav 299564 by: Ashley Sheridan 299565 by: acetrader 299566 by: Devendra Jadhav Re: Converting tables into forms 299560 by: David Robley Re: Classes and Functions 299567 by: Martin Scotta Re: What PHP version are you using? 299568 by: O. Lavell 299569 by: Israel Ekpo 299570 by: Martin Scotta 299571 by: John Black 299572 by: Bob McConnell 299573 by: John Black 299574 by: Israel Ekpo 299575 by: John Black 299576 by: Lester Caine Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- From: Lex Braun [mailto:lex.br...@gmail.com] Sent: segunda-feira, 2 de Novembro de 2009 02:58 To: MEM Cc: php-gene...@lists.php.net Subject: Re: [PHP] RE: Help with my first recursion menu Hi, On Sat, Oct 31, 2009 at 11:07 AM, MEM tal...@gmail.com wrote: From: Lex Braun [mailto:lex.br...@gmail.com] Sent: sábado, 31 de Outubro de 2009 14:05 To: MEM Cc: php-gene...@lists.php.net Subject: Re: [PHP] RE: Help with my first recursion menu Hi, On Wed, Oct 28, 2009 at 5:22 PM, MEM tal...@gmail.com wrote: I've been told that stack is the way to go, so I'm trying to understand the following code: http://pastebin.com/m5616c88f I've commented every line so that any of you could see if I'm interpreting something wrong: I have two questions about this code, that hopefully someone on the list could explain: 1) Why do we need to remove the last array item? (on line 32): array_pop($urlStack); On line 20, $url creates an URL path that includes the $cat path. Once you've completed iteration on all children of $cat, the url path should no longer include $cat path, thus it is removed from $urlStack. 2) Why we print the closed tag of the li element, after the recursive call? (on line 29) echo /li\n; Line 29 is closing the li element that was opened on line 23 for $cat. Thanks a lot in advance, Márcio -Lex Thanks a lot. I knew that: “Line 29 is closing the li element that was opened on line 23 for $cat.” My question intend to be more like: Why that line to close the li element is *after* the recursive call? Somehow, it seems that instead of creating something like this: ul liitem1/li liitem2/li liitem3/li /ul We are doing: ul liitem1 liitem2 liitem3 /li /ul Say you have a tree menu that contains : $arr = array('item1' = 'Item 1', 'item2' = array('item2a' = 'Item 2a', 'item2b' = 'Item 2b')); $urlStack = array('category'); When you call the tree() function with the above $arr values, the function acts as follows: 1. First time through the function, the opening ul element is printed 2. First time through the foreach loop sets $cat = 'item1' and $val = 'Item 1'. 3. As this is not an array, the else condition prints liItem 1/li 4. Second time through the foreach loop sets $cat = 'Item 2' and $val = array('item2a' = 'Item 2a', 'item2b' = 'Item 2b'). 5. As this is an array, the if condition prints lia href=''Item/a and calls the tree function recursively 6. Second time through the tree function, another ul element is printed and the two sub items are printed as lisub item/li as they do not contain additional arrays. Tree function ends by printing the closing /ul tag. 7. The foreach loop from step 5 continues and prints the closing /li. Tree function ends by printing the closing /ul tag. The output from calling tree($arr, $urlStack) would thus be: ul liItem 1/li li a href=?path=category/Item 2Item 2/a ul liItem 2a/li liItem 2b/li /ul /li /ul Perfectly clear. Thanks a lot Lex. :) ---End Message--- ---BeginMessage--- Hey, You can do it this way as well $myFeedHTML .= TH ROWSPAN=3 BGCOLOR='#99CCFF' $feedItemImagePath br / br / input type='Button' value='Edit' width='100px' onClik=\javascript: DeleteChannelAndAllOfItsFeeds()\ / br / br /DELETEbr //TH; So you can escape double quotes by \ (slash) try this .. It will work... you can escape any special character that you want to use as it is by prepend it by \ On Mon, Nov 2, 2009 at 2:23 PM, acetrader saliba...@gmail.com wrote: Hi there, I am doing an application that allows me to create RSS channels and put feeds inside of each channel. Everything works so far, but - now I have started to do the 'Edit Channel', 'Edit Feed',
Re: [PHP] Re: What PHP version are you using?
On Mon, Nov 2, 2009 at 2:15 PM, John Black s...@network-technologies.orgwrote: Bob McConnell wrote: I just checked the Red Hat 5.4 manifest and it shows php-5.1.6-23.el5 - php-5.1.6-23.2.el5_3. CentOS simply repackages the Red Hat kit without the proprietary bits. I don't understand why they are so far behind on a build that was just released last month, but our hosting service only provides what's in the official release. I just check the CentOS repo and the repo lists php-5.1.6-23.2.el5_3.x86_64.rpm as latest. So CentOS is as upto date as RedHat, the way it should be. -- John Define: Ubuntard = The drivel this guy spews is inane and forgettable stuff, characterized by comments that treat Ubuntu as if it is the only distribution in existence. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That is not good. 5.1.6 was released in August 2006. More than 3 years ago. There are a lot of bug fixes since then http://www.php.net/ChangeLog-5.php It looks like the php libraries are not maintained in CentOS and Red Hat Repositories. -- Good Enough is not good enough. To give anything less than your best is to sacrifice the gift. Quality First. Measure Twice. Cut Once.
Re: [PHP] Re: What PHP version are you using?
Israel Ekpo wrote: That is not good. 5.1.6 was released in August 2006. More than 3 years ago. There are a lot of bug fixes since then http://www.php.net/ChangeLog-5.php It looks like the php libraries are not maintained in CentOS and Red Hat Repositories. I posted the current RHEL version because, personally, I would look at the latest release of one of the biggest Enterprise class Linux vendors before deciding on a PHP version. The larger distros only tend to upgrade packages when required because other packages need them or when a security issues has been discovered. Other times they will patch in security fixes applied to packages. The tradeoff here is that you get something older but the system you receive is solid. I run ARCH Linux on my home system because I like to test the latest releases BUT I want stable software on my servers. -- John They hurt you at home and they hit you at school, They hate you if you're clever and they despise a fool, Till you're so fucking crazy you can't follow their rules... [John Lennon] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: What PHP version are you using?
Israel Ekpo wrote: On Mon, Nov 2, 2009 at 2:15 PM, John Black s...@network-technologies.orgwrote: Bob McConnell wrote: I just checked the Red Hat 5.4 manifest and it shows php-5.1.6-23.el5 - php-5.1.6-23.2.el5_3. CentOS simply repackages the Red Hat kit without the proprietary bits. I don't understand why they are so far behind on a build that was just released last month, but our hosting service only provides what's in the official release. I just check the CentOS repo and the repo lists php-5.1.6-23.2.el5_3.x86_64.rpm as latest. So CentOS is as upto date as RedHat, the way it should be. That is not good. 5.1.6 was released in August 2006. More than 3 years ago. There are a lot of bug fixes since then http://www.php.net/ChangeLog-5.php It looks like the php libraries are not maintained in CentOS and Red Hat Repositories. There are very good reasons why a 'long time supported' build does not keep replacing packages all the time. It is gauranteed NOT to change them, so compatibility problems introduced by PHP such as the 'date' problem will not come up and bit ANY of their customers. I believe that there is a new version due on a couple of 'long time supported' distributions, but the current 'instability' with PHP5.3 potentially requiring changes to deployed applications is the sort of thing that these builds are supposed to avoid. I'll be staying with 5.2.x for a while simply because I know that is stable with my current code base. So it IS good that a stable and understood build of PHP is used as no one would gaurantee that later builds will not introduce problems - especially following a change of minor versions. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Custom function for inserting values into MySQL
Okay friends, I have been wondering about writing a simple function that will help me with my MySQL inserting. Not because I need to save time and space, but because I wanted to. I wrote a function for inserting 10 values (I have not been able to come up with an idea how to make the number of values I'm inserting variable, so I'm sticking with ten). This function takes 22 parameters: #1 is the table name, #2-21 are the row names and the values, and #22 is the integar string. The first 21 parameters are self-explanatory, the 22nd is a string of values that need to be inserted as an integar, basically, not adding single quotes around the value. Eg. $value2 = 5, not $value2 = '5'. I am very hesitant to try this one out on my database, I've got tables of important information and don't want to, I don't know, inadvertantly throw a wrench into the works, AND I want to open up a dialoug about custom PHP functions for working with MySQL, for the fun of it! Here is my 10 value function for inserting data into a MySQL database table. function insertinto10($table, $field1, $value1, $field2, $value2, $field3, $value3, $field4, $value4, $field5, $value5, $field6, $value6, $field7, $value7, $field8, $value8, $field9, $value9, $field10, $value10, $int = NULL) { if (isset($int)) { $sPattern = '/\s*/m'; $sReplace = ''; $int = preg_replace($sPattern, $sReplace, $int); $pieces = explode(,, $int); // $pieces[0], $pieces[1] - each equal to value numbers that are integars $length = count($pieces); // call custom function to create associative array eg. $newarray[2] = 1, $newarray[4] = 1, $newarray[5] = 1 . . . $integarArray = strtoarray($length, $int); } $valuesArray = array($value1, $value2, $value3, $value4, $value5, $value6, $value7, $value8, $value9, $value10); foreach ($valuesArray as $key = $value) { if (isset($integarArray[$key]) $integarArray[$key] == 1) { // INTEGAR VALUE $valuesArray[$key] = mysql_real_escape_string(stripslashes($value)); } else { // STRING VALUE $cleanValue = mysql_real_escape_string(stripslashes($value)); $valuesArray[$key] = '{$cleanValue}'; } } $result = mysql_query(INSERT INTO `{$table}` (`{$field1}`, `{$field2}`, `{$field3}`, `{$field4}`) VALUES ({$valuesArray[1]}, {$valuesArray[2]}, {$valuesArray[3]}, {$valuesArray[4]}, {$valuesArray[5]}, {$valuesArray[6]}, {$valuesArray[7]}, {$valuesArray[8]}, {$valuesArray[9]}, {$valuesArray[10]})); return $result; } You may find copying/pasting into your favorite code-editor helps make it more readable. Do you see any major hangups or screwups on first glance? And is my fear of trying this out on my database unfounded? Does this even seem that useful?
RE: [PHP] Custom function for inserting values into MySQL
Do you see any major hangups or screwups on first glance? Yes. There is so much wrong with this I don't even know where to begin... This function takes 22 parameters: #1 is the table name, #2-21 are the row names and the values, and #22 is the integar string. Dude. Seriously? TWENTY TWO parameters. Use this for variable number of parameters: http://us2.php.net/manual/en/function.func-get-args.php Or how about using an array/hash as your second parameter with the field=value pairs. Which is astonishing since you have the concept of an array with this hack: $valuesArray = array($value1, $value2, $value3, $value4, $value5, $value6, $value7, $value8, $value9, $value10); foreach ($valuesArray as $key = $value) The word you're looking for is INTEGER not INTEGAR. And is my fear of trying this out on my database unfounded? No. Don't use it. Does this even seem that useful? No. Your function is so very limited in scope and use. You're better off writing a wrapper around the SQL functions and submit direct SQL as the string parameter to the function. See attached db.inc.php. You would also be better served using a method/function such as my base.class.php::sync() which will insert or update a row. The attached code is about a year old or so and has since been refined further, but this should give you a good place to start. http://daevid.com ?php #--- # # Confidential - Property of Lockdown Networks, Inc. # Do not copy or distribute. # Copyright 2002-2008 Lockdown Networks, Inc. All rights reserved. # #--- require_once('global.inc.php'); require_once('error.class.php'); class baseClass { protected $db = 'V2_Data'; protected $table= NULL; protected $id = NULL; protected $created_on = NULL; protected $_stamp = NULL; protected $enabled = TRUE; //we use generic __call __get and __set, but this is a special case. function get_stamp(){ return $this-_stamp; } function set_stamp($stamp) { $this-_stamp = $stamp; } /** * Constructor * * @access public * @return object * @parammixed $id the ID of the object to load from the database (this could be a string or usually an integer) * @author Daevid Vincent [dae...@] * @version 1.2 * @date 09/20/07 */ function __construct($id = NULL) { if ($_SESSION['companydb']) $this-db = $_SESSION['companydb']; //this follows the Ruby way for ease of porting/sharring, please stick with the convention. if (is_null($this-table) preg_match( '/y$/', $this-getClassname() ) 0) $this-table = strtolower(preg_replace( '/y$/', 'ies', $this-getClassName() )); elseif( is_null( $this-table ) ) $this-table = strtolower($this-getClassName()).'s'; if (!is_null($id)) $this-load($id); } /** * generate a key/value pair from the class' variables. * * @access public * @return array * @author Daevid Vincent [dae...@] * @version 1.0 * @date 08/13/07 */ public function get_array() { $row = array(); foreach($this as $key = $value) $row[$key] = $value; $row['enabled'] = ($this-enabled) ? 1 : 0; return $row; } /** * set the class' values based upon a SQL query. * * Note: Usually this is called by an extension class, * which in turn calls the parent::load_from_sql() * which generates an array and then calls load_from_array() * * @access public * @return array or false * @paramint $id ID of the object to load * @author Daevid Vincent [dae...@] * @version 1.0 * @date 08/20/07 * @see load_from_array() */ function load($id = null) { if (intval($id) 1) return false; $sql = SELECT * FROM.$this-db...$this-table. WHERE id = '.SQL_ESCAPE($id).'; $result = $this-load_from_sql($sql); //LIMIT 1 is appended by base class if ($result) return $result; else throw
Re: [PHP] Custom function for inserting values into MySQL
I would take a look at some of the frameworks like codeignter to see how they do things. But like Davied mentioned a simpler way to handle the passing into the function would be Function save($table, $data) Where data is an array of key value pairs which takes your 22 parameters down to 2. The array could look like $data = array('id' = 1, 'name' = 'bob' ...) Bastien Sent from my iPod On Nov 2, 2009, at 8:32 PM, Allen McCabe allenmcc...@gmail.com wrote: Okay friends, I have been wondering about writing a simple function that will help me with my MySQL inserting. Not because I need to save time and space, but because I wanted to. I wrote a function for inserting 10 values (I have not been able to come up with an idea how to make the number of values I'm inserting variable, so I'm sticking with ten). This function takes 22 parameters: #1 is the table name, #2-21 are the row names and the values, and #22 is the integar string. The first 21 parameters are self-explanatory, the 22nd is a string of values that need to be inserted as an integar, basically, not adding single quotes around the value. Eg. $value2 = 5, not $value2 = '5'. I am very hesitant to try this one out on my database, I've got tables of important information and don't want to, I don't know, inadvertantly throw a wrench into the works, AND I want to open up a dialoug about custom PHP functions for working with MySQL, for the fun of it! Here is my 10 value function for inserting data into a MySQL database table. function insertinto10($table, $field1, $value1, $field2, $value2, $field3, $value3, $field4, $value4, $field5, $value5, $field6, $value6, $field7, $value7, $field8, $value8, $field9, $value9, $field10, $value10, $int = NULL) { if (isset($int)) { $sPattern = '/\s*/m'; $sReplace = ''; $int = preg_replace($sPattern, $sReplace, $int); $pieces = explode(,, $int); // $pieces[0], $pieces[1] - each equal to value numbers that are integars $length = count($pieces); // call custom function to create associative array eg. $newarray [2] = 1, $newarray[4] = 1, $newarray[5] = 1 . . . $integarArray = strtoarray($length, $int); } $valuesArray = array($value1, $value2, $value3, $value4, $value5, $value6, $value7, $value8, $value9, $value10); foreach ($valuesArray as $key = $value) { if (isset($integarArray[$key]) $integarArray[$key] == 1) { // INTEGAR VALUE $valuesArray[$key] = mysql_real_escape_string(stripslashes($value)); } else { // STRING VALUE $cleanValue = mysql_real_escape_string(stripslashes($value)); $valuesArray[$key] = '{$cleanValue}'; } } $result = mysql_query(INSERT INTO `{$table}` (`{$field1}`, ` {$field2}`, `{$field3}`, `{$field4}`) VALUES ({$valuesArray[1]}, {$valuesArray [2]}, {$valuesArray[3]}, {$valuesArray[4]}, {$valuesArray[5]}, {$valuesArray[6]}, {$valuesArray[7]}, {$valuesArray[8]}, {$valuesArray[9]}, {$valuesArray[10]})); return $result; } You may find copying/pasting into your favorite code-editor helps make it more readable. Do you see any major hangups or screwups on first glance? And is my fear of trying this out on my database unfounded? Does this even seem that useful? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php