[PHP] Question regarding OO
?php /* I have a question here regarding object orientation in PHP and any other language. Let's start with some hypothetical code: */ // --- 1st CLASS class ParkingLot { var size; // size in sq feet var max_number_of_cars; // how many cars there is space for function __construct($size, $max_cars) { $this-size = $size; $this-max_number_of_cars = $max_cars; } }; cpark = new ParkingLot(5, 17); // --- 2nd CLASS class ParkingSpace extends ParkingLot { var ps_ID; // ID of the parking space ( 1 .. max_number_of_cars ) var occupied_by; // ID of the car on the parking space var st_time; // Unix time stamp set when the car parks function __construct($car, $id) { $this-st_time = time(); $this-occupied_by = $car; $this-ps_ID = $id; } }; /* OK, so i got a parking lot class and its subclass parking space. Now the question: I want a list of occupied parking spaces, where do I put that? One might put it into the ParkingLot Class, but wouldn't that be a recursion (a child instance in the parent class)? */ $occ_parking_spaces = array(); $occ_parking_spaces[] = new ParkingSpace('Joes Car', 8); $occ_parking_spaces[] = new ParkingSpace('My Prshe', 17); $occ_parking_spaces[] = new ParkingSpace('Toms Caddy', 4); /* After a while a method to print all occupied spaces is necessary. Correct me if I'm wrong, but I usually add it to the ParkingLot class. class ParkingLot { // previous code ... var $occ_parking_spaces = array(); function print_occ_spaces() { var_dump($this-occ_parking_spaces) } }; What bothers me here is that I'm actually having a list of child classes in the parent class, is there a better/correct way to do this? I hope I made myself clear. Greetz, Yeti */ ?
[PHP] IPv6 validation
Hello community, I have been working with alot of IPv6 lately. Now i was wondering of what there might be the best way to validate an IPv6 address. Couldn't think of any working regexp, since even ::1 or :: is valid (localhost), so i tried it the following way: ?php //RFC 4291 //http://tools.ietf.org/html/rfc4291 function validate_ipv6($value) { if (substr_count($value, :) 2) return false; // has to contain : at least twice like in ::1 or 1234::abcd if (substr_count($value, ::) 1) return false; // only 1 double colon allowed $groups = explode(':', $value); $num_groups = count($groups); if (($num_groups 8) || ($num_groups 3)) return false; // 3-8 groups of 0-4 digits (1 group has to be at leas 1 digit) $empty_groups = 0; foreach ($groups as $group) { $group = trim($group); if (!empty($group) !(is_numeric($group) ($group == 0))) { if (!preg_match('#([a-fA-F0-9]{0,4})#', $group)) return false; } else ++$empty_groups; } return ($empty_groups $num_groups) ? true : false; // the unspecified address :: is not valid in this case } var_dump(validate_ipv6(::)); // false (wanted result) var_dump(validate_ipv6(::1)); // true var_dump(validate_ipv6(1234::abcd)); // true var_dump(validate_ipv6(2001:DB8:0:0:8:800:200C:417A)); // true var_dump(validate_ipv6(0:0:0:0:0:0:0:1)); // true var_dump(validate_ipv6(0:0:0:0:0:0:0:0)); // false (wanted result) var_dump(validate_ipv6(:::::::)); // false (wanted result) var_dump(validate_ipv6(2001:0DB8::CD30::::)); // true var_dump(validate_ipv6(FF01:0:0:0:0:0:0:101)); // true var_dump(validate_ipv6(bananas)); // false var_dump(validate_ipv6(1:2:3:4:5:6:7:8:9)); // false ? anybody with better ideas? Yeti
Re: [PHP] IPv6 validation
It will still take some time until every provider has PHP5 running, at least where I am from. I have many customers who want me to get their sites running on some cheap webspace they got along with their internet connection. Then you have to tell them it won't work because of some problem with the versions. I would love to write code for PHP5+ only. On 7/12/08, Eric Butera [EMAIL PROTECTED] wrote: On Sat, Jul 12, 2008 at 9:13 AM, Bernhard Kohl [EMAIL PROTECTED] wrote: Doesnt filter_var() require PHP5+ ? I have quite some systems still running 4.4.8. On 7/12/08, Kevin Waterson [EMAIL PROTECTED] wrote: This one time, at band camp, Yeti [EMAIL PROTECTED] wrote: Now i was wondering of what there might be the best way to validate an IPv6 address. from this url.. http://phpro.org/tutorials/Filtering-Data-with-PHP.html#9 ?php /*** an IP address ***/ $ip = 2001:0db8:85a3:08d3:1319:8a2e:0370:7334; /*** try to validate as IPV6 address ***/ if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) { echo $ip is not a valid IP; } else { echo $ip is valid; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php PHP4 has been deprecated forever now. Step up to the plate and get with 5, especially if you're still writing new code.
Re: [PHP] case and accent - insensitive regular expression?
I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php Many thanks again for your effort, I'm definitely on the good way Giulio I was intrigued by your example, so I played around with it some more this morning. My own quick web search yielded a lot of results for highlighting search terms, but none that I found did what you're after. (I admit I didn't look very deep.) I was up to something like this before your reply came in. It's still by no means complete. It even handles simple English plurals (words ending in 's' or 'es'), but not variations that require changing the word base (like 'daisy' to 'daisies'). ?php function highlight_search_terms($phrase, $string) { $non_letter_chars = '/[^\pL]/iu'; $words = preg_split($non_letter_chars, $phrase); $search_words = array(); foreach ($words as $word) { if (strlen($word) 2 !preg_match($non_letter_chars, $word)) { $search_words[] = $word; } } $search_words = array_unique($search_words); foreach ($search_words as $word) { $search = preg_quote($word); /* repeat for each possible accented character */ $search = preg_replace('/(ae|æ|ǽ)/iu', '(ae|æ|ǽ)', $search); $search = preg_replace('/(oe|œ)/iu', '(oe|œ)', $search
Re: [PHP] case and accent - insensitive regular expression?
Oh, and i forgot about this one ... jorge at seisbits dot com wrote on 11-Jul-2008 09:04 If you try to make a strtr of not usual charafters when you are in a utf8 enviroment, you can do that: function normaliza ($string){ $string = utf8_decode($string); $string = strtr($string, utf8_decode( ÂÊÎÔÛÀ), -AEIOU); $string = strtolower($string); return $string; } On Tue, Jul 15, 2008 at 11:38 AM, Yeti [EMAIL PROTECTED] wrote: I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php Many thanks again for your effort, I'm definitely on the good way Giulio I was intrigued by your example, so I played around with it some more this morning. My own quick web search yielded a lot of results for highlighting search terms, but none that I found did what you're after. (I admit I didn't look very deep.) I was up to something like this before your reply came in. It's still by no means complete. It even handles simple English plurals (words ending in 's' or 'es'), but not variations that require changing the word base (like 'daisy' to 'daisies'). ?php function highlight_search_terms($phrase, $string) { $non_letter_chars = '/[^\pL]/iu'; $words = preg_split($non_letter_chars, $phrase
Re: [PHP] case and accent - insensitive regular expression?
The original problem was User X submits a character string A. A PHP scripts uses A to search for it's occurences in a DB, ignoring special characters. The result of ze search is a list of character strings M-LIST with matches. This list gets outputted to the user X, but before that all the matching strings should be replaced with 'span style=color: #FF'..'/span' If i clearly got the OP then he is using MySQL to perform the search. I guess he is doing it with MATCH. So MySQL already found the match and in PHP it has to be done again ... eg. The table has 2 entries, string1 and string2 .. string1 = 'Thís ís an éxámplè stríng wíth áccénts.' string2 = 'This is an example string without accents.' Now the user searches for ample: search = '*ample*' Both string have matches due to accent-insensitivity (AI). Now the result is outputted with highlighting .. *Thís ís an éx*span style=color: #FF*ámplè*/span* stríng wíth áccénts.* *This is an ex*span style=color: #FF*ample*/span* string without accents.* So since MySQL already did the job, why not get the occurances from it? I'm not an MySQL expert, but I know google and found something called string functions. Especially a locate function got my interest. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate Now shouldnt it be possible to create a query that searches the db for matches and additionally uses the string function? I have no idea, but maybe some MySQL-expert out there has ... Yeti On Tue, Jul 15, 2008 at 7:17 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Tue, Jul 15, 2008 at 12:30 PM, tedd [EMAIL PROTECTED] wrote: At 10:15 AM -0400 7/15/08, Andrew Ballard wrote: On TueWell, OK, I can think of one optimization. This takes advantage of the fact that preg_replace can accept arrays as parameters. In a couple very quick tests this version is roughly 30% faster than my previous version: -snip- Hey, when you finally get finished with that function, please let me know I would like to copy it. :-) Cheers, tedd All yours. I figure I'm done with it. (At least until I actually need to use it for something and then I have to test it for real. :-) ) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] After INSERT form submit - Data doesn't refresh!
ok, in that case forget the Last-Modified or set it to the current date. header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); Did you turn caching off in your browser and try it then? Or try it with a different browser? On Tue, Jul 22, 2008 at 2:48 PM, Rahul S. Johari [EMAIL PROTECTED] wrote: Here's what it is: I have a php page, a.php, which contains these three things: - SELECT statement to display records from a mySQL Table - HTML Form for inserting data into the mySQL Table - INSERT statement to insert that row into the mySQL Table The HTML Form submits to the same, a.php Once the user submits the Form, a.php is called which INSERT's the row into the mySQL Table. However, the row does not appear in the SELECT statement table data unless I hit refresh on the page. (The INSERT function is executed before the SELECT in the page). I used the header() code that was suggested: header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache'); $ffile = 'a.php'; $time = filemtime($ffile); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); .. but it didn't help. Everything is working fine except that the Browser is more then likely caching the data and thus not allowing the newly inserted row to appear on top when the SELECT is executed. On Jul 22, 2008, at 8:34 AM, Thiago H. Pojda wrote: Code, please? :) On Tue, Jul 22, 2008 at 9:33 AM, Rahul S. Johari [EMAIL PROTECTED] wrote: Hmm, interesting. In my case, $file does indeed output dynamic data. I did try with the modified time but it still doesn't work. I still have to hit refresh on the browser, after submitting the form, in order for the inserted record to appear. Not sure what to do - it's rather annoying. Novice users of the page would assume the entry didn't get inserted or something happened. One alternate is to submit Data to a different page and let that page redirect to the Original page - but I do find it hard to believe that there is no solution to this caching. Thanks guys! On Jul 22, 2008, at 8:26 AM, Yeti wrote: The Last-Modified header tells the browser when the requested page was last modified. Now I don't know how you get the date in your case but here is an example: browser requests /test/test.php which is a simple php file without any includes etc. in this case $file = '/test/test.php'; This wont work if $file outputs dynamic data, so only use it if the content only changes when you change the file. Now if you are using templates etc. obtaining the Last-Modified time is a bit more complicated. If you use server side caching then you can chose the cached file else you have to figure it out yourself. And the RFC 2616 header specification says: An origin server MUST NOT send a Last-Modified date which is later than the server's time of message origination. In such cases, where the resource's last modification would indicate some time in the future, the server MUST replace that date with the message origination date. So do not send a future date! On Tue, Jul 22, 2008 at 2:11 PM, Rahul S. Johari [EMAIL PROTECTED] wrote: I tried with just the first three header() statements you gave, but it didn't work. Let me try the modification date ... which file is being referred to in $ffile? Also, I'm using Firefox, if it's of any consequence. Thanks! On Jul 22, 2008, at 7:30 AM, Bernhard Kohl wrote: I'm pretty sure this is a cache issue .. To disable caching: header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache'); But if you have the modification date then use $time = filemtime($ffile); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); On Tue, Jul 22, 2008 at 1:14 PM, Rahul S. Johari [EMAIL PROTECTED] wrote: Ave, I'm wondering if there's a PHP solution to this, I could be in the wrong place. I have an INSERT form which submits to the same php page, which also displays the records from the mySQL database the INSERT form submits to. When the form submits and the page returns, the added record does not show up unless you Refresh the page. I'm imagining even after form submit, the Browser is caching the data and displaying data from the Cache. Is there a solution to this? Is there anything PHP can do to instruct the browser not the cache the data? Thanks! --- Rahul Sitaram Johari Founder, Internet Architects Group, Inc. [Email] [EMAIL PROTECTED] [Web] http://www.rahulsjohari.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Rahul Sitaram Johari Founder, Internet Architects Group, Inc. [Email] [EMAIL PROTECTED] [Web] http://www.rahulsjohari.com --- Rahul Sitaram
[PHP] Reference or copy?
Hello everyone, Many of you may be familiar with references in PHP. Now i read somewhere in the PHP manual that creating references can take longer than copies. PHP5+ also seems to reference a bit different thant PHP4 did. Here is some working example code: ?php class useless { var $huge_array; function __construct() { $this-huge_array = array(); for ($i = 0; $i 1024; $i++) $this-huge_array[] = $GLOBALS; // fill ze array with copies of $GLOBALS array return true; } function useless() { return $this-__construct(); } } $time_start = microtime(true); $test_obj = new useless(); $time_end = microtime(true); $time = $time_end - $time_start; echo It took {$time} seconds without using the reference operator.\r\n; unset($test_obj); $time_start = microtime(true); $test_obj = new useless(); $time_end = microtime(true); $time = $time_end - $time_start; echo It took {$time} seconds using the reference operator.\r\n## with obj2 \r\n; $time_start = microtime(true); $test_obj = new useless(); $obj2 = $test_obj; $time_end = microtime(true); $time = $time_end - $time_start; echo It took {$time} seconds without using the reference operator.\r\n; unset($test_obj); $time_start = microtime(true); $test_obj = new useless(); $obj2 = $test_obj; $time_end = microtime(true); $time = $time_end - $time_start; echo It took {$time} seconds using the reference operator.\r\n; ? I tested the code in PHP 4.4.7 and in PHP 5.2.5 and the results were pretty much the same. Using references speeds up the script! Occasionally obj2-with-references took longer than all the others. But i don't know if that's to be taken serious. Now if i do not need a copy, isn't it smarter to use references instead? I'm grateful for any ideas, thoughts or experiences Yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reference or copy?
?php # So if i want a copy in PHP, like: $a = $b; # In PHP5 $a would still be a reference as long as $b is not being changed?(!) # Such behaviour makes it extremely easy to write a speedy script without worrying about copy/reference issues! # Thanks to all of you, # Ernie ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing my own web based user forum
If I fully understood the question you were asking then no. Since it seems you are using a database there is no need to serialize. You can write a simple function that fetches user data from a DB query and then creates the object. If you are going to use sessions you will have to do that only when the user logs in and for verification purposes of whatever kind. You might think of something similar to: http://webbytedd.com/b1/simple-session/ In your original post you did not mention a picture upload site so I suggest it is about uploading pictures to the forum/attaching them to a thread. I do not really have an idea of how your site will be operating, but I guess you analyze the GET parameters and include files according to them. Some code might be helpful to explain what you want On Fri, Aug 1, 2008 at 2:52 PM, Jason Pruim [EMAIL PROTECTED] wrote: So are you suggesting, create the users in the forum, and then just serialize/unserialize when needed to store the info so when they go to the picture upload side it queries the forum database? On Aug 1, 2008, at 8:07 AM, Bernhard Kohl wrote: ?php #User authentication should not be a problem at all. #If you want it simple just serialize a user class and write it to a file or into a DB. class user { var $username; var $pw; function set_user($name, $pw) { $this-pw = md5($pw); $this-username = $name; return true; } } $new_user = new user(); if ($new_user-set_user('Joe', 'swordfish') { $fp =@ fopen('/some_dir/users.txt', 'a'); @fwrite($fp, serialize($new_user)); @fclose($fp); } # the next time you need it simple read it in again with unserialize() ? On Fri, Aug 1, 2008 at 1:49 PM, Jason Pruim [EMAIL PROTECTED] wrote: Hi Everyone, I am looking at writing my own web based user forum somewhat for my own knowledge, and because I know that I don't know enough to be able to tie in authentication so they only need 1 user account. Does anyone have any examples short of downloading something like phpbb and tearing it apart? It will probably be really light weight, basic forum that hopefully will expand into more as time goes on :) I've tried searching the web but have not been able to turn up any help unless I was to write a bridge for a song... Any knowledge you can bestow upon me is greatly appreciated! Thanks! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Internationalisation and MB strings
?php *# Hello Community # Internationalisation, a topic discussed more than enough and YES, I am looking forward to PHP6. # But in reality I still have to develop for PHP4 and that's where the dog is burried ^^ # We have a customer here who is running a small site, but still in five different languages. # Lately he started complaining about some strange site behaviours: # He has a discussion board where people can post their ideas, comments etc. Nothing special # Every post has a maximum length of 2048 characters, which is checked by JavaScript at the Browser # and after submitting the form by PHP. # Our mistake was to use strlen();* global $cc_strlen; global $cc_mb; $cc_strlen = $cc_mb = 0; if (array_key_exists('text', $_POST)) { $cc_strlen = strlen($_POST['text']); $cc_mb = mb_strlen($_POST['text'], 'UTF-8'); *// new code* if ($cc_strlen 2048) { /* snip */ } // do something } /* snip */ // do something *#this works fine as long as the user only submits single byte charachters, but with UTF-8 the whole thing changes ..* ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titletest/title /head body pYou submitted ?php echo $cc_strlen; ? characters (STRLEN)./p pYou submitted ?php echo $cc_mb; ? characters (MB_STRLEN)./p pCharacters Left:span id=remainder2048/span/p form action= method=post onsubmit=return false; id=post_form textarea id=post_text name=text onkeydown=check_length(); onchange=check_length(); rows=10 cols=50œŸŒ‡Ņ/textareabr / input type=submit value=Submit id=post_button onclick=submit_form(); / /form script type=text/javascript !-- var the_form = document.getElementById('post_form'); var textarea = document.getElementById('post_text'); var counter = document.getElementById('remainder'); function check_length() { var remainder = 2048 - textarea.value.length; var length_alert = false; if (remainder 0) { remainder = 0; for (var count = textarea.value.length; (count = 2048); (count -= 1)) { textarea.value = textarea.value.substr(0, 2047); counter.style.color = 'red' length_alert = true; } } if (length_alert) alert('You are already using 2048 characters.'); if (document.all) { counter.innerText = remainder; } else { counter.textContent = remainder; } } function submit_form() { check_length(); the_form.submit(); alert ('You submitted ' + textarea.value.length + ' characters'); return true; } -- /script ?php *# Now as soon as one is starting to submit UTF-8 characters strlen is not working proberly any more # So we had to work through thousands of lines of code, replacing strlen() with mb_strlen(); # We also found mb_strlen to take about 8 times longer than strlen().* $s_t = microtime(); mb_strlen('œŸŒ‡Ņ', 'UTF-8'); $e_t = microtime(); echo 'pMB_STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds/p'; $s_t = microtime(); strlen('œŸŒ‡Ņ'); $e_t = microtime(); echo 'pSTRLEN took : '.(($e_t - $s_t)*1000).' milliseconds/p'; *# So much for internationalisation. # Just writing this as a reminder for everyone who is facing similar situations.* ? /body /html
Re: [PHP] Internationalisation and MB strings
Oh right. Doing 1 measurement only is not even worth a theory. Well, I'm wondering how much PHP can speed that result up, since we are calling the same function with the same parameter 1 times. Wouldn't it be even more realistic if we called it with changing strings? ?php $iterations = 1; $mb_array = array(); for ($i = 0; $i $iterations; ++$i) $mb_array[] = str_shuffle('œŸŒ‡Ņ'); $s_t = microtime(true); foreach ($mb_array as $mb_string) { mb_strlen($test_string, 'UTF-8'); } $e_t = microtime(true); echo 'pMB_STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' milliseconds/p'; $s_t = microtime(true); foreach ($mb_array as $mb_string) { strlen('œŸŒ‡Ņ'); } $e_t = microtime(true); echo 'pSTRLEN took : '.(($e_t - $s_t)*1000/$iterations).' milliseconds/p'; ? MB_STRLEN took : 0.0525826 milliseconds STRLEN took : 0.0020655 milliseconds I could not find out how well str_shuffle supports multi byte strings in PHP4, so I'm wondering if I did this right .. On Fri, Aug 1, 2008 at 5:06 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Fri, Aug 1, 2008 at 9:50 AM, Yeti [EMAIL PROTECTED] wrote: ?php *# Hello Community # Internationalisation, a topic discussed more than enough and YES, I am looking forward to PHP6. # But in reality I still have to develop for PHP4 and that's where the dog is burried ^^ # We have a customer here who is running a small site, but still in five different languages. # Lately he started complaining about some strange site behaviours: # He has a discussion board where people can post their ideas, comments etc. Nothing special # Every post has a maximum length of 2048 characters, which is checked by JavaScript at the Browser # and after submitting the form by PHP. # Our mistake was to use strlen();* global $cc_strlen; global $cc_mb; $cc_strlen = $cc_mb = 0; if (array_key_exists('text', $_POST)) { $cc_strlen = strlen($_POST['text']); $cc_mb = mb_strlen($_POST['text'], 'UTF-8'); *// new code* if ($cc_strlen 2048) { /* snip */ } // do something } /* snip */ // do something *#this works fine as long as the user only submits single byte charachters, but with UTF-8 the whole thing changes ..* ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titletest/title /head body pYou submitted ?php echo $cc_strlen; ? characters (STRLEN)./p pYou submitted ?php echo $cc_mb; ? characters (MB_STRLEN)./p pCharacters Left:span id=remainder2048/span/p form action= method=post onsubmit=return false; id=post_form textarea id=post_text name=text onkeydown=check_length(); onchange=check_length(); rows=10 cols=50œŸŒ‡Ņ/textareabr / input type=submit value=Submit id=post_button onclick=submit_form(); / /form script type=text/javascript !-- var the_form = document.getElementById('post_form'); var textarea = document.getElementById('post_text'); var counter = document.getElementById('remainder'); function check_length() { var remainder = 2048 - textarea.value.length; var length_alert = false; if (remainder 0) { remainder = 0; for (var count = textarea.value.length; (count = 2048); (count -= 1)) { textarea.value = textarea.value.substr(0, 2047); counter.style.color = 'red' length_alert = true; } } if (length_alert) alert('You are already using 2048 characters.'); if (document.all) { counter.innerText = remainder; } else { counter.textContent = remainder; } } function submit_form() { check_length(); the_form.submit(); alert ('You submitted ' + textarea.value.length + ' characters'); return true; } -- /script ?php *# Now as soon as one is starting to submit UTF-8 characters strlen is not working proberly any more # So we had to work through thousands of lines of code, replacing strlen() with mb_strlen(); # We also found mb_strlen to take about 8 times longer than strlen().* $s_t = microtime(); mb_strlen('œŸŒ‡Ņ', 'UTF-8'); $e_t = microtime(); echo 'pMB_STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds/p'; $s_t = microtime(); strlen('œŸŒ‡Ņ'); $e_t = microtime(); echo 'pSTRLEN took : '.(($e_t - $s_t)*1000).' milliseconds/p'; *# So much for internationalisation. # Just writing this as a reminder for everyone who is facing similar situations.* ? /body /html You can't determine timing by simply calling each function one time. I changed your script to the following: ?php $iterations = 1; $s_t = microtime(true); for ($i = 0; $i $iterations; ++$i) { mb_strlen('œŸŒ‡Ņ', 'UTF-8'); } $e_t = microtime(true); echo 'pMB_STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' milliseconds/p'; $s_t = microtime(true); for ($i = 0; $i $iterations; ++$i) { strlen('œŸŒ‡Ņ'); } $e_t = microtime(true
Re: [PHP] Not found regex
?php $file = '/example/hello.php'; $info = pathinfo($file); $not_allowed = array('php', 'pt', 'exe'); if (!in_array(strtolower($info['extension']), $not_allowed)) { // do something } // why use a regex? ? On Mon, Aug 4, 2008 at 4:44 PM, Manoj Singh [EMAIL PROTECTED] wrote: Hello All, I have to create the regular expression to allow all the file extensions except the specified extension. Suppose I want to allow extensions with php, so the regex is: ^.+\.php$ But here i need the regex which allows all the extensions except php. I will appreciate any help. Best Regards, Manoj Kumar Singh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] An appeal to your better nature
Backups? What's that? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
How about this one? function recursive_mkdir($dir) { if (is_dir($dir)) return true; if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } On Thu, Aug 21, 2008 at 1:04 AM, Ashley Sheridan [EMAIL PROTECTED] wrote: Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk -- Forwarded message -- From: Jochem Maas [EMAIL PROTECTED] To: Robert Cummings [EMAIL PROTECTED] Date: Thu, 21 Aug 2008 00:52:09 +0200 Subject: Re: [PHP] Does this seem wrong to anyone else? Robert Cummings schreef: On Wed, 2008-08-20 at 14:09 -0700, Stephen Johnson wrote: I am debugging someone else¹s code, and this is what they have : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. I am not an expert on this particular type of thing, and maybe that is allowed, but it seems wrong to me, and this error is being generated: That's the point of recursion... to recursively call oneself! Fatal error: Call to undefined function mkdir_recursive() in x.php on line 1057 the call to mkdir_recursive() on line 1057 is made inside mkdir_recursive() so it's impossible that the function doesn't exist ... unless the function you posted is actually a method of a class, in which case some time in the past the project included a standalone function mkdir_recursive() which is been removed. at least that would be my first/best guess. Not sure why you're getting that error since it appears to be well defined above... unless x.php is not the same file in which mkdir_recursive() ha sbeen defined. I'll wager it's not... in which case you need to ensure the file that contains the mkdir_recursive() function declaration is included into x.php. BTW, FWIW, I wouldn't call the above code good quality since it obfuscates its intent by using || hackishness. It's succinct but less obvious. it's plain horrid, not to mention using is_dir() dirname() twice unnecessarily, providing no checks as to whether the path exists and is a file or whether file permissions are okay (if your gonna wrap mkdir() might as well do a proper job) , etc. worst of all the call to mkdir() is error suppressed ... a nice big wtf waiting to happen when it fails. oh and there is absolutely no need to use recursion here, a while loop could be used instead which would be more efficient. lastly Stut pointed out that php5 negates the need for this function altogether, but you might still be stuck on php4 for some reason. ain't it fun inheriting other peoples 'code' ;-) Cheers, Rob. -- 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] Re: concatenating with . or ,
So it is faster to output various strings using the , instead of .? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] concatenating with . or ,
That is why i love this list. Always something new to learn. What I am still wondering about is if it is faster to use commas or the {} brackets? ( I don't know how that technique is called, since I'm not a walking dictionary) Example: $var = blah blah; echo $var,test; echo {$var}test; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] concatenating with . or ,
Bernhard wrote: echo $test_string, $array_value; It seems like they echoed them -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex for email validation
?php # this one worked fine for me, but it does not cover the full RFC like: name [EMAIL PROTECTED] OR name [EMAIL PROTECTED] $regex = ^[a-z0-9,!#\$%'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%'\*\+/=\?\^_`\{\|}~-]+)[EMAIL PROTECTED](\.[a-z0-9-]+)*\.([a-z]{2,})$; if (eregi($regex, $email)) { // do something } # Beware that the filter functions only work under PHP5+. If your PHP supports them they should be the preferred choice ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex for email validation
That Rx.com domain name is really great stuff, but how do you expect the average user to type it in? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with HTML special characters
I'm wondering why you are using uuml;. If you had your site in UTF-8 it would not be necessary. Even google is using UTF-8 these days. I guess your browser automaticly converts the uuml; in your textarea into the namespace-proper ü. You could try using htmlentities to convert the into amp; or use a different namespace. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: concatenating with . or ,
There we go .. from concatenation to Who knows a song nobody can guess right?. Crazy Horses - The Osmonds http://www.youtube.com/watch?v=MyRiNZDb5EY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to write good code
Ross McKay [EMAIL PROTECTED] wrote: Find out what bad is by reading this: http://thedailywtf.com/Series/CodeSOD.aspx Then, don't do it like that! What I enjoyed most on that page was this comment: One day, after a code review by one of our 'senior' developers this little beauty showed up... #define NUMBER_OF_BITS_IN_BYTE 8 The justification was... that the byte might change and no 'magic' numbers should appear in the code... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Google Chrome
I uninstalled it precisely beacause of this behaviour. The disk was running crazy every time chrome was started. And I don't know how to do lsof | grep chrome on Windows to see what's going on. LSOF for winblows: http://download.sysinternals.com/Files/ProcessMonitor.zip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ASCII Captcha
Not so good if you're using lynx, or if you're blind, I guess. I often tell my clients the reasons for accessibility and usually i get the answer We don't have any blind customers so we don't care about them. So much for fair play in the web. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing an array from PHP to Javascript
I would use an unserializer. http://code.activestate.com/recipes/414334/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION array problems [ANOTHER SOLUTION]
register_globals has been deprecated as of PHP6. So writing PHP code to work without global registering not just prevents variable poisoning, it also increases the life span of your scripts. I still wonder if using php_flag register_globals off in .htaccess might affect servers running PHP4 and using safe mode as in ... http://forum.mamboserver.com/showthread.php?t=44514 A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Manipulating strings
?php #let's say we got following string: $some_string = 'br /blah blahbr /blah blahbr /'; var_dump(explode('br /', $some_string)); /* OUTPUT: array(4) { [0]= string(0) [1]= string(9) blah blah [2]= string(9) blah blah [3]= string(0) } */ #So as you see index 0 and index 3 are empty strings. Keep that in mind ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RewriteRule
#.htaccess RewriteEngine on RewriteBase / #Apache recurses into htaccess 3 times so we have to make sure not to overwrite an already processed rule RewriteCond %{REQUEST_URI} !^.*(\.php|\.css|\.js|\.html|\.ico|robots\.txt).*$ #The rewrite condition below can be used to pass through GET parameters (direct access) #RewriteCond %{THE_REQUEST} !^.*\?getparam1=.*$ # /blog/*/**/*** - blog.php?getparam1=*getparam2=** #RewriteRule /blog[/]{0,}([a-zA-Z0-9 ]{1,})[/]{0,}([a-zA-Z0-9 ]{1,})[/]{0,}[.*]{0,}$ blog.php?getparam1=$1getparam2=$2 RewriteRule ^blog[/]{0,}([^/]{0,})[/]{0,}([^/]{0,})[/]{0,}.*$ blog.php?getparam1=$1getparam2=$2 [NC,QSA,L] # All not found requests -- somefile.php ErrorDocument 404 /somefile.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Alternative to HTTP_REFERER?
By definition: The referer, or HTTP referer, identifies, from the point of view of an internet webpage or resource, the address of the webpage (commonly the URL, the more generic URI or the i18n updated IRI) of the resource which links to it. More detail at: http://en.wikipedia.org/wiki/Referer http://tools.ietf.org/html/rfc2616 So is a redirecting page a referrer or not? I don't know. Had no time to translate the gibberish. I experimented a bit with it and the most suitable solution I found was passing the referring page on with a GET parameter ... ## A page redirecting to test.php ## ?php $location = (empty($_SERVER[REQUEST_URI])) ? 'Location: test2.php' : 'Location: test2.php?ref='.urlencode(base64_encode(gzdeflate($_SERVER[REQUEST_URI], 8))); header($location); ? ## test.php ## !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titleReferrer Test Page/title script type=text/javascript alert('Referrer ('+(typeof document.referrer)+'['+document.referrer.length+']): '+document.referrer); /script /head body h1Referred page/h1 ? $page = ($_GET['ref']) ? @gzinflate(base64_decode(urldecode($_GET['ref']))) : 'not found'; echo REFERRER h2Referring page: $page/h2 REFERRER; ? /body /html # A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: HTML5 canvas tag
I'm not very familiar with the whole thing yet but after looking at your site I find it quite interesting. So is it possible to render 3d vector based objects in the canvas and if so an entire 3d based website? Are there any 3d libraries yet like OpenGL for applications? It would be quite handy to describe 3d/2d objects or styles with a language like CSS. Do you think that will be possible in the near future? A yeti. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RewriteRule
What's the point of using '{0,}' instead '*' ? Well the thing is that with the {0,} more REQUEST_URIs are valid: eg. /blog /blog/ /blog/17 /blog/17/ /blog/17/0 /blog/17/0/ AND additional characters get ignored (like when it is necessary to reload content with javascript, due to caching issues) /blog/17/0/ignored_string -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RewriteRule
Jessen wrote: RewriteRule ^blog/([^/]+)/([^/]+)/ blog.php?getparam1=$1getparam2=$2 [NC,QSA,L] Of course, your truely does what the OP asked for + it cuts of all strings after the last / /A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RewriteRule
You are absoloodle right about that. Although I'm not sure about their greediness, which might be different. I prefer the '{0,}' in my rewrite rules because I usually define the max-length to prevent code injection. eg. # to make sure only the first 8 chars get passed on to PHP RewriteRule ^blog/([^/]{0,8} index.php?a=$1 [NC,QSA,L] So that's why they ended up in my reply. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Pure PHP Templating Class/AJAX Problem
Well after looking at the template thing you posted with your link it seems to me like PHP is used to create working XML. So i wonder why you are using AJAX here. Now could it be that you use appendChild() ? That function would simply add the XML again. It's not easy to tell if you are not showing the JavaScript code .. Still it simply depends on how you are importing the node you get from XMLHttpRequest() or responseXML Btw. importNode() is not working on all Browsers .. Below is a code snipped I use for my AJAX class in JavaScript to copy a node of one XML document (like from responseXML) into another. It works in IE6+ and all W3C compliant browsers. To make this work you will still have to make some ajustments. xml_obj.prototype.xml_import_node = function(node, to_node, all_children) { // cross browser importNode, NOTE: if toNode not specified it will be set to current root_element // appends node as a child to to_node // if all_children is true then all child nodes will be imported too /* NOTE TYPES: ELEMENT_NODE = 1; ATTRIBUTE_NODE = 2; TEXT_NODE = 3; CDATA_SECTION_NODE = 4; ENTITY_REFERENCE_NODE = 5; ENTITY_NODE = 6; PROCESSING_INSTRUCTION_NODE = 7; COMMENT_NODE = 8; DOCUMENT_NODE = 9; DOCUMENT_TYPE_NODE = 10; DOCUMENT_FRAGMENT_NODE = 11; NOTATION_NODE = 12; */ if (!node) return false; if (!this.DOC) this.DOC = document; if (!to_node.nodeType) { if (!this.XML) return false; try { to_node = this.XML.documentElement; this.DOC = this.XML; } catch(e) { return false; } } try { if (!node.nodeType) return false; switch (node.nodeType) { case 1: // new element var new_node = this.DOC.createElement(node.nodeName); if (node.attributes (node.attributes.length 0)) { // if it has attributes for (var count = 0; (count node.attributes.length); count++) { this.xml_import_node(node.attributes[count], new_node); } } if (all_children (node.childNodes (node.childNodes.length 0))) { // if child nodes var dump = null; for (var count = 0; (count node.childNodes.length); count++) { this.xml_import_node(node.childNodes[count], new_node, true); } } to_node.appendChild(new_node); return new_node; break; case 2: // new attribute var name = node.nodeName; switch (node.nodeName.toLowerCase()) { case 'onload': case 'onunload': case 'onblur': case 'onclick': case 'ondblclick': case 'onfocus': case 'onkeydown': case 'onkeypress': case 'onkeyup': case 'onmousedown': case 'onmousemove': case 'onmouseout': case 'onmouseover': case 'onmouseup': var eval_code = 'to_node.'+node.nodeName.toLowerCase(); eval_code += ' = function() { '+node.nodeValue+' };'; eval(eval_code); break; case 'style': to_node.style.cssText = node.nodeValue; // IE FIX // no break case 'class':
Re: [PHP] Re: 1 last error to fix before the application is done!
Ok, so empty is faster. I appreciate the time you guys took to bench the thing. But I'm still gonna use array_key_exists. If you like it or not. Using it a couple of times in my scripts will slow them down a few nanoseconds. That's plain evil mwhahaha. //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP to get File Type
function get_file_extension($file) { http://us2.php.net/manual/en/function.pathinfo.php ?php $path_parts = pathinfo('/www/htdocs/index.html'); echo $path_parts['dirname'], \n; echo $path_parts['basename'], \n; echo $path_parts['extension'], \n; echo $path_parts['filename'], \n; // since PHP 5.2.0 ? Secondly the MIME type can differ from the extension (file suffix) It's the same with uploaded files. Although the browser sends the MIME type it might not be the right one, since browsers obtain the MIME by checking the extension. //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 1 last error to fix before the application is done!
You might also want to try array_key_exists if (array_key_exists('loggedin', $_SESSION['userInfo'])) { // do something with $_SESSION['userInfo']['loggedin'] } //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP to get File Type
Is there any function in PHP to get the file/Mime type of any file? check this out: http://us2.php.net/manual/en/function.finfo-open.php //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: 1 last error to fix before the application is done!
Personally, I very rarely see the point in using array_key_exists... It's a function call and has overhead where as isset() and empty() are language constructs and (I would hope) are much more efficient (although I've not done any benchmarks) # i don't know what's wrong with this .. $foo = array(); $foo['bar'] = null; if (array_key_exists('bar', $foo)) { switch ($foo['bar']) { case true: //do something break 1; default: //do something else } } # if that's causing more overhead then let me see your benchmark, then i believe it -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Information on Cookies
You encrypt stuff with a string that you keep secret. That string is needed to decrypt the string. I recommend you change that string once in a while. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Securing AJAX requests with PHP?
but whose counting :-)) Someone is for sure. Maybe the scheduler? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Securing AJAX requests with PHP?
Ok, but how safe are tokens? Thinking of man in the middle attacks they do not make much sense, do they? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: what's the difference in the following code?
I would understand it if it was like this .. ?php $search = isset($_GET['search']) ? $_GET['search'] : ''; # versus if (isset($_GET['search'])) { $search = $_GET['search']; } ? In the first statement $search would either be set to $_GET['search'] or an empty string, whereas in the second statement $search would only be set, if there is a $_GET['search'] //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: what's the difference in the following code?
Wrong. They are equivalent. The second is probably just easier to follow with a clearly defined default value outside the conditional block. Well, leaving out the default value at the 2nd if statement makes a difference and that's what I did. Here is the code I changed again .. Set to $_GET['search'] or an empty string ?php $search = isset($_GET['search']) ? $_GET['search'] : ''; ? Only set if there is a $_GET['search'] ?php // no default value if (isset($_GET['search'])) $search = $_GET['search']; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Securing AJAX requests with PHP?
True, but then my permission / auth / workflow schema defines all that. the user won't like have that permission, the request will be logged and nothing is ever deleted from the app in any case since I only allow soft (record level flag ) deletes to ensure data integrity I agree with Bastien here. If you can't trust your authorized users then don't authorize them to delete entries. I would also recommend some kind of access control to lower the risk of a complete data loss. Use HTTPS to prevent man in the middle attacks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what's the difference in the following code?
OP = original poster (in this case I guess) http://acronyms.thefreedictionary.com/OP So it's all about making code readable and probably easier to maintain (even people unfamiliar with the script). Doesn't that render the ternary operator IF-statement unnecessary? Have I been totally wrong using it in countless scripts of mine (always thought it's a neat way to do if )? Somebody please tell me that I do not have to rewrite my code base now, since I care about security. Btw. PHP's ternary inconsistency here .. http://en.wikipedia.org/wiki/%3F:#Inconsistency_of_implementations And how about this .. switch(isset($_GET['search'])) { case true: $search = $_GET['search']; break 1; default: $search = ''; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: -help
-help: invalid argument I like the way you handle input errors in your php-general subroutines David. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem changing file encoding
A neat way to transcode between different encodings is htmlentities and html_entity_decode [1, 2] EXAMPLE: ?php # encode a string in UTF-8 to html entities $string = 'øæåöäü'; $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); # transcode it into ISO-8859-15 $string = html_entity_decode($string, ENT_QUOTES, 'ISO-8859-15'); ? There was a user with a similar problem at phpbuilder forums [3]. Have a closer look at it. [1] http://us2.php.net/manual/en/function.htmlentities.php [2] http://us2.php.net/manual/en/function.html-entity-decode.php [3] http://www.phpbuilder.com/board/archive/index.php/t-10334612.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: -help
Well maybe it is because he has register_globals on why he is not printing a list of valid arguments. imagine something like this .. @php-generals$ [PHP] -help List of valid arguments: -c, --make-me-forget erases the built-in mainframe's short term memory -f, --flush-me erases the entire memory of the built-in mainframe -h, --help prints this list -s, --show-bank-data prints the bank account data -u, --user username for login -p, --password passphrase for login @php-generals$ [PHP] -u ' ; return true;' -p ' ; shell_exec('su god');' -s -c Login successful! Welcome to the built-in mainframe god. --- Bank account data --- * * * ** ** ** ** ** *** *** *** --- [EMAIL PROTECTED] dd if=/dev/zero of=/dev/sda; exit; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Difficulty navigating symlinks
If you are in control of you DNS records you could CNAME [1] the sites to the same address, where a PHP script or RewriteRule [2] loads the specific configuration by checking the requested URI. Since you got them on the same server anyways this would not cost any performance. [1] http://www.zytrax.com/books/dns/ch8/cname.html [2] http://marc.info/?l=php-generalm=122383066714789w=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MkDir Help
If you are prior PHP5 write your own recursive mkdir function [1] as posted on this list a while ago. [1] http://marc.info/?l=php-generalm=121926660406116w=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Inheritance of class methods
Using extends means that a class IS-A substructure of its parent class(es). EXAMPLE: class plant { }; class tree extends plant { }; class apple_tree extends tree { }; apple_tree inherits all methods and attributes from plant and tree So if there was a methods plant-growth() you can also call it from tree and apple_tree IS-A versus HAS-A apple_tree IS-A tree apple_tree HAS-A fruit called apple So apple does not extend apple_tree because it is not a tree EXAMPLE: class apple { var color = 'blue'; var inhabitant = 'worm'; } class apple_tree extends tree { var apples = array(new apple()); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] export data to a ms excel file using php
I'm not into MS Office, but isn't there some weird Office XML format since Office 2007? At MSDN I could find a nice description of the wannabe standard [1]. So if the new Excel can take XML it wouldn't be too difficult to export the data I guess. [1] http://msdn.microsoft.com/en-us/library/aa338205.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what's the difference in the following code?
The difference between the examples are still nothing, it do the same. But I never use the short version of if, because when I look after some month in some projects I have a better overview when there is a long if , its much easier to extend. As explained a couple of times already - there is not supposed to be a difference. It's about security and making code maintainance easier. [quote to Chris's former post] (..) imagine you're manually reviewing a colleague's code, and you're looking through a few thousand lines to try to help identify security problems. (..) [end quote] It's the old What's good code and what's bad code? discussion. In this case ternary operations are bad code. sorry for my bad english Die Code tun nicht Unterschiede in Execution. Es ist Sicherheits Frage. sorry for my bad German //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Building an array, kind of?
?php $arr = array(1234, 1235, 1236, 1237, 1238, 1239); $string = implode(', ', $arr); var_dump($string); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] clear a mysql table
I used to have a similar problem What I did was to define a max number of cashed pages. So when reaching that number I simply did it the FIFO way -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Interactive canvas example
It worked for me. Although I had some quite CPU intensive processes running, so it lagged a bit. Had no time to look into the code, so I was wondering if you could answer my question ... That yellow information box popping up onclick(), is it drawn by JS or is it something like a hidden div? Congratulations on that one //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Interactive canvas example
JS I suppose. Though it creates a DIV element on demand. The function in question is RGraph.Tooltip() in RGraph.common.js. OK, I found it. Thank you for showing me. I was thinking of something similar recently. /** * Shows a tooltip next to the mouse pointer * * @param text The tooltip text * @return The tooltip object - a DIV */ RGraph.Tooltip = function (canvas, text, x, y) { /** * Hide any currently shown tooltip */ if (RGraph.tooltip) { RGraph.tooltip.style.display = 'none'; RGraph.tooltip = null; } /** * Show a tool tip */ var obj = document.createElement('DIV'); obj.style.position= 'absolute' obj.style.backgroundColor = '#E1'; obj.style.border = '1px solid #333'; obj.style.borderRight = '2px solid #333'; // Set the right and bottom borders to be a little thicker - gives the effect of a drop shadow obj.style.borderBottom= '2px solid #333'; // Set the right and bottom borders to be a little thicker - gives the effect of a drop shadow obj.style.display = 'block' obj.style.visibility = 'visible'; obj.style.paddingLeft = '3px'; obj.style.paddingRight= '3px'; obj.style.fontFamily = 'Tahoma'; obj.style.fontSize= '10pt'; obj.innerHTML = text; document.body.insertBefore(obj, canvas); obj.style.left= (canvas.offsetLeft) + x + 3; obj.style.top = (canvas.offsetTop + y) - obj.offsetHeight; /** * Install the function for hiding the tooltip. * * FIXME Not sure how this will affect any existing document.onclick event */ document.body.onclick = function () { RGraph.tooltip.style.display = 'none'; } /** * Keep a reference to the object */ RGraph.tooltip = obj; } Now I wonder why you are creating a new tooltip each time the user clicks on the graph? Why not do it the following way? RGraph.Tooltip = function (canvas, text, x, y) { try { if (RGraph.tooltip) { // if tooltip already drawn RGraph.tooltip.innerHTML = text; RGraph.tooltip.style.left = (canvas.offsetLeft) + x + 3; RGraph.tooltip.style.top = (canvas.offsetTop + y) - RGraph.tooltip.offsetHeight; } else { // create tooltip if not drawn yet var obj = document.createElement('DIV'); obj.style.position= 'absolute' obj.style.backgroundColor = '#E1'; obj.style.border = '1px solid #333'; obj.style.borderRight = '2px solid #333'; // Set the right and bottom borders to be a little thicker - gives the effect of a drop shadow obj.style.borderBottom= '2px solid #333'; // Set the right and bottom borders to be a little thicker - gives the effect of a drop shadow obj.style.display = 'block' obj.style.visibility = 'visible'; obj.style.paddingLeft = '3px'; obj.style.paddingRight= '3px'; obj.style.fontFamily = 'Tahoma'; obj.style.fontSize= '10pt'; /* //alternatively one could create a tooltip css class since this is presentation obj.className = 'tooltip'; //IE obj.setAttribute('class', 'tooltip'); // W3C DOM */ document.body.insertBefore(obj, canvas); RGraph.tooltip = obj; document.body.onclick = function () { RGraph.tooltip.style.left = '-999'; //older opera fix } return RGraph.Tooltip(canvas, text, x, y); } return RGraph.tooltip; // return tooltip obj as stated in functions comment } catch(e) { return false; } } Secondly CanvasTextFunctions.letters() really is in a class of its own. And why dont you use prototype [1]? [1] http://www.w3schools.com/jsref/jsref_prototype_array.asp //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parsing URLs
One could also abuse basename and pathinfo. Works in PHP4+ ?php $uri = 'http://www.domain.com/page/file/'; $pathinfo = pathinfo($uri); $webpageaccess = array(); $webpageaccess[1] = $webpageaccess[2] = ''; if (isset($pathinfo['basename'])) $webpageaccess[1] = $pathinfo['basename']; if (isset($pathinfo['dirname'])) $webpageaccess[2] = basename($pathinfo['dirname']); //var_dump($webpageaccess); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex validation
If your trying to filter E-Mail addresses, then filter_var is what you should use: http://php.net/filter_var If the OP (original poster) got PHP5+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex validation
On Wed, Oct 29, 2008 at 5:36 AM, [EMAIL PROTECTED] wrote: When it comes to email validation, I would recommend using the IMAP function which will be both fast and correct: http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php Otherwise, it's guaranteed that you are having at least some false positives, and probably some false negatives. Didn't know about those IMAP functions. And they even work in PHP4. Thanks for telling. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bitwise operation giving wrong results
Usually in PHP one does not take much care about the data types, but in this case you absoloodle have to. If you use bit operators on a character then its ascii number will be taken instead (how should a number based operation work with a string?) also if you pass on $_GET params directly into ay bitwise operation you might get some un-nice behaviour. So check them first. ?php $a = $b = false; if (is_numeric($_GET['b'].$_GET['a'])) { $a = (int)$_GET['a']; $b = (int)$_GET['b']; echo $a $b; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Printing JPEG
If you are on a linux box with lpr [1] running you could try a shell_exec() in combination with imagemagick [1] http://tldp.org/HOWTO/Printing-Usage-HOWTO-2.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex validation
After ceo posted about the imap function I was eager to try it out and got rather disappointed pretty soon. imap_rfc822_parse_adrlist() should not be used for email validation! EXAMPLE: ?php var_dump(imap_rfc822_parse_adrlist('! # $ % * + - / = ? ^ _ ` { | } ~', '')); ? The above code will output: array(1) { [0]= object(stdClass)(2) { [mailbox]= string(36) ! # $ % * + - / = ? ^ _ ` { | } ~ [host]= string(0) } } Although ! # $ % * + - / = ? ^ _ ` { | } ~@example.com would be a valid email address! Without the '@example.com' it is not. Have a look at the user comments at [1], where one user has further examples. [1] http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex validation
ceo wrote: var_dump(imap_rfc822_parse_adrlist('! # $ % * + - / = ? ^ _ ` { | } ~', '')); This looks like a valid localhost email address to me... It surely is a valid localhost email address, but what most people (and the OP) usually need is to validate a full email string with a local and a domain part. What should be valid email addresses according to RFC 2822 [1]: !#$%*+-/=?^_`{|[EMAIL PROTECTED] @@example.com Not valid email addresses: \@example.com @@example.com - [EMAIL PROTECTED] Valid email addresses according to the Multipurpose Internet Mail Extension (MIME) [2]: [EMAIL PROTECTED] [EMAIL PROTECTED] So for people who got to write code that also works on PHP4 it is not very easy to validate an email address. Even nice regex attempts like [3] fail since more and more mail servers support the MIME hieroglyphs. That's why I was pretty excited about imap_rfc822_parse_adrlist(), since it runs in PHP4 if installed. Which clearly is no substitute for the PHP5+ filter functions [4]. If it's just my brain farting and there actually then tell me. [1] http://www.faqs.org/rfcs/rfc2822.html [2] http://en.wikipedia.org/wiki/MIME [3] http://www.addedbytes.com/php/email-address-validation/ [4] http://in.php.net/filter
Re: [PHP] Mailing lists
Even a four year old girl would think that's too pink, Rich. What's wrong with pink? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mailing lists
My 5-year-old had pretty much the same discussion with his sister -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions in object oriented code
OK I guess it's somehow like this .. form ?php if (isset($_POST['submit'])) { include('sessions.php'); // include sessions.php } ? !-- form innerhtml -- /form now this of course is something very bad to do and it wont work. One way to prevent markup from being outputted is using ob_buffer() [1] EXAMPLE: ?php $form = FORM form !-- form inner xml -- /form FORM; ob_start(); echo $form; $output_buffer = ob_get_contents(); ob_end_clean(); var_dump(nl2br(htmlentities($output_buffer))); ? So what we do here is simply start the output buffer befor echoing $form. ob_get_contents() returns the outputbuffer as it is right now. By calling ob_end_clean() buffering is stopped and the buffer cache released. Still keep in mind that headers will still be sent when buffering the output. here is a more complex EXAMPLE: ?php ob_start(); // starting the output buffer ? html body !-- inner xml -- {{replace_me}} /body /html ?php $output_buffer = ob_get_contents(); ob_end_clean(); session_start(); $_SESSION['test'] = time(); echo str_replace('{{replace_me}}', 'pThis is the replaced string.br /SESSION[test] was set to: '.$_SESSION['test'].'/p', $output_buffer); ? Now we start the output buffer at the beginning of the script and the session at the end. It does not matter whether we close the PHP tag after starting the ob_buffer. ( like with ? ) As long as we do not flush_end or clean_end the output buffering process it will continue caching the output (except headers). So session_start should work after actually outputting markup. Another method could be like we did above the str_replace() [2] ... EXAMPLE: ?php $some_number = time(); $html = HTML html body pTime: $some_number/p p{{replace_me}}/p /body /html HTML; echo str_replace('{{replace_me}}', 'This string was changed by PHP', $html); ? There is still plenty of other possible solutions. Keep on rocking [1] http://in.php.net/manual/en/ref.outcontrol.php [2] http://in.php.net/manual/en/function.str-replace.php //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions in object oriented code
I can't really understand that. Not sure if you understand my problem properly (if I've not explained properly). Anyone can give me some solutions please? Well as long as you don not provide any code it's all just wild guesses. What I tried was to show you a way of simply preventing the HTML from being sent to the browser before you include the session and/or cookie file. So you would just have to add the output buffering syntax to your existing code without changing all the scripts. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] removing text from a string
?php $filename = .htaccess; $fp =@ fopen($filename, r) or die (Couldn't open $filename); // ENTER ENCODING HERE .. $encoding = 'UTF-8'; if ($fp) { while (!feof($fp)) { $thedata =@ fgets($fp); // if every number is defonoodle separated by a dot .. if (is_string($thedata)) { $position_of_dot = mb_strpos($thedata, '.', 0, $encoding); if (is_numeric($position_of_dot) ($position_of_dot = 0)) $thedata = trim(mb_substr($thedata, $position_of_dot, mb_strlen($thedata, $encoding), $encoding)); } //print the modified line and \n } } @fclose($fp); ? [mb_strpos] http://in.php.net/manual/en/function.mb-strpos.php [mb_substr] http://in.php.net/manual/en/function.mb-substr.php //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Grouping records
I have transactional records with the following structure Records of what kind? Is it SQL? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: removing text from a string
ltrim($line, '0123456789 .'); I am feeling a bit boneheaded now. How easy things can be. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: removing text from a string
Replying to myself now. On Tue, Nov 4, 2008 at 7:40 AM, Yeti [EMAIL PROTECTED] wrote: ltrim($line, '0123456789 .'); I am feeling a bit boneheaded now. How easy things can be. This would not work if the character string after the number started with a number too. EXAMPLE ?php $line = '017. 85 apples were sold to customer John Doe.'; # now ltrim would clearly cut off the '85 ' which belongs to the sentence. var_dump(ltrim($line, '0123456789 .')); ? So if one still wanted the speedy string functions a simple trim() [1] or another ltrim() [2] would have to be added. EXAMPLE ?php $line = '017. 85 apples were sold to customer John Doe.'; var_dump(ltrim((ltrim($line, '0123456789.'), ' ')); ? Still there is one flaw in this construct: If there was no white space between the '017.' and the '85 apples ..' we get the old mishap again. EXAMPLE ?php $line = '017.85 apples were sold to customer John Doe.'; # note the difference above: '017.85 apples ...' this time var_dump(ltrim((ltrim($line, '0123456789.'), ' ')); ? To stick with the string functions one could either use the strpos($line, '.') + substr() [3] method or do it with explode(), implode() [4]: EXAMPLE ? $line = '017.85 apples were sold to customer John Doe.'; $line = explode('.', $line); unset($line[0]); $line = implode('.', $line); ? So it seems that the regular expressions posted are not a bad choice after all. //A yeti [1] http://in.php.net/manual/en/function.trim.php [2] http://in.php.net/manual/en/function.ltrim.php [3] http://marc.info/?l=php-generalm=122580865009265w=2 [4] http://in.php.net/manual/en/function.explode.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Grouping records
Ok, this looks quite databasey so I guess you will have a query like: SELECT Rowid, Person, Timediff FROM transitional_records ORDER BY Timediff I don't know what DB you use. let's say it is MySQL (the others are similar). Always provide such things when asking for advice. Else it's not easy to help. EXAMPLE ?php mysql_connect(localhost, mysql_user, mysql_password) or die(Could not connect: . mysql_error()); mysql_select_db(mydb); $result = mysql_query(SELECT Rowid, Person, Timediff FROM transitional_records ORDER BY Timediff); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // do something with the result here } mysql_free_result($result); ? So what we get is an array like this .. array ( Person = (string), Timediff = (numeric) ); Rowid, Person and Timediff are the only Values we need to get each entries Groupid. Now back to our example .. EXAMPLE ?php mysql_connect(localhost, mysql_user, mysql_password) or die(Could not connect: . mysql_error()); mysql_select_db(mydb); $result = mysql_query(SELECT Rowid, Person, Timediff FROM transitional_records ORDER BY Timediff); $persons = array(); // array containing each persons current Groupid $rowids = array(); // array containing each row's groupid while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $rowids[$row['Rowid']] = 0; // default for a row's groupid if ($row['Timediff'] 60) { if (!isset($persons[$row['Person']])) $persons[$row['Person']] = 0; ++$persons[$row['Person']]; } if (isset($persons[$row['Person']])) $rowids[$row['Rowid']] = $persons[$row['Person']]; } var_dump($rowids); mysql_free_result($result); ? So what is that script doing? Well, first of all we set 2 arrays $persons and $rowids; $persons is some sort of buffer for each person's current Groupid whilst processing the table entries. $rowids contains Groupid for each Row (set whilst processing) WHILE LOOP: First the current row's Groupid is set to the default value, which is zero ( $rowids[CURRENT_ID] = 0 ). Then we check whether the Timediff of the current row is greater than 60 or not. IF it is the person's current Groupid is incremented ( $persons[CURRENT_PERSON] += 1 ) After the IF statement the current rowid's Groupid is changed to $persons[CURRENT_PERSON] if that one exists. As result we should get an array $rowids with the Groupid for each array. So simply loop through that array and have the database SET the Groupid somehow like this .. EXAMPLE ?php foreach ($rowids as $row = $group) { echo SQL UPDATE transitional_records SET Groupid = $group WHERE Rowid = $row; SQL; } ? I hope I could help a little Be more specific next time //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Электронная реклама 648-67-61 все адреса и базы Москвы и России
Command unkown. Make sure you typed it right. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] basic php question...
Do disability browsers support JavaScript? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Secure redirection?
I wonder why you redirect the page via php when the browser supports JavaScript Why not let JS do the redirect after the XMLHttpRequest? figurative code .. if (BROWSER DOES NOT SUPPORT JS) header(Location: http://$host$url;); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ??????????? ??????? 648-67-61 ??? ?????? ? ???? ?????? ? ??????
no comment -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fopen not working corectly on remote IIS
As PHP says ... there seems to be something wrong with file permissions. Make sure the IIS-user (if there is one on windows) can read intekendb.php. I don't know if you checked [1] yet. It's alot of useful info about php on IIS. Quote out of that article: The IIS user (usually IUSR_MACHINENAME) needs permission to read various files and directories, such as php.ini, docroot, and the session tmp directory. Maybe [2] can help you out too. [1] http://www.php.net/manual/en/install.windows.iis.php [2] http://at.php.net/manual/en/function.fopen.php#50601 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Recursive Static Method
Some code would be quite helpful here. But your scenario should not make any problem. EXAMPLE: ? class foo { static function test() { static $count; $count++; echo Call {$count}br /; include_once('test.php'); } } foo::test(); ? EXAMPLE (@file: test.php): ?php if (class_exists('foo')) { foo::test(); } exit(); ? OUTPUT: Call 1br /Call 2br / //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegEx to check for non-Latin characters
Hi Behzad, I would try a different approach ... EXAMPLE (UTF-8): !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titlePersia/title /head body ?php $username = '1aﺠﺟﺝﭻﭽﭼﭺ2b; $encoding = 'utf-8'; $username = mbStringToArray($username, $encoding); foreach($username as $char) { if (strlen($char) == 1) echo $char.' is not a multibyte characterbr /'; } function mbStringToArray ($string, $encoding) { $strlen = mb_strlen($string); while ($strlen) { $array[] = mb_substr($string,0,1,$encoding); $string = mb_substr($string,1,$strlen,$encoding); $strlen = mb_strlen($string); } return $array; } ? /body /html As you can see I'm using the multibyte string functions [1] and split $username into a character by character array. Then I use strlen() for which an UTF-8 char has a length 1. Note: This might change with PHP6. It also does not check for Persian characters only yet. You would have to try something like this ... EXAMPLE (UTF-8): !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titlePersia/title /head body ?php $username = '1aﺠﺟﺝﭻﭽﭼﭺ2b'; $encoding = 'utf-8'; $chars = 'ﺐﺒﺑﺏﭗﭙﭙپﺖﺘﺗﺕﺚﺜﺛﺙﺞﺠﺟﺝﭻﭽﭼﭺﺢﺤﺣﺡﺦﺨﺧﺥﺪﺪﺩﺩﺬﺬﺫﺫﺮﺮﺭﺭﺰﺰﺯﺯﮋﮋژژﺲﺴﺳﺱﺶﺸﺷﺵﺺﺼﺻﺹﺾﻀﺿﺽﻂﻄﻃﻁﻆﻈﻇﻅﻊﻌﻋﻉﻎﻐﻏﻍﻒﻔﻓﻑﻖﻘﻗﻕﮏﮑﮐکﮓﮕﮔگﻞﻠﻟﻝﻢﻤﻣﻡﻦﻨﻧﻥﻮﻮووﻪﻬﻫﻩﯽﻴﻳﻯ'; $username = mbStringToArray($username, $encoding); foreach($username as $char) { if (strlen($char) == 1) echo $char.' is not a multibyte characterbr /'; if (mb_strpos($chars, $char, 0, $encoding) !== false) echo $char.' is a Persian characterbr /'; } function mbStringToArray ($string, $encoding) { $strlen = mb_strlen($string); while ($strlen) { $array[] = mb_substr($string,0,1,$encoding); $string = mb_substr($string,1,$strlen,$encoding); $strlen = mb_strlen($string); } return $array; } ? /body /html [1] http://in.php.net/manual/en/ref.mbstring.php [2] http://in.php.net/manual/en/function.strlen.php
Re: [PHP] Days until Easter and Christmas
I guess Canadians are slower, eh? :-) LOL -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Experience (was: while-question)
who says PHP means programming? All I see is script code, unless you write your own extension or you contribute to php-internal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Experience (was: while-question)
Ok, ok I admit it. PHP is a programming language. I guess I drank too much assembly code today. By the way ... Motorola 68000! Those were to good old days. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] implode()
with implode one can reverse the function arguments i know .. but ?php $BannerSize = ''; if (isset($_POST['BannerSize']) is_array($_POST['BannerSize'])) { $BannerSize = implode(',', $_POST['BannerSize']); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: phpDesigner 2008?
Yes, NetBeans became my favourite too a while ago. And it runs on many Operating Systems, is free and has a debugger. I also like the way it handles projects. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] anchor name on URL
If you do not escape the name attribute you might run into trouble when using XHTML. Always escape attributes properly. GOOD: ?php echo HEREDOC div style=padding-bottom: 1500px;div style=padding-bottom: 1500px; a href=#aynchoor title=some_aynchoor name=some_aynchoorClick me/a /div div style=padding-bottom: 1500px; background-color: #f00baa; a href=#some_aynchoor title=aynchoor name=aynchoorClick me too/a /div HEREDOC; ? BAD: ?php echo 'a href=#aynchoor title=some_aynchoorClick me'; echo 'a href=#some_aynchoor title=aynchoor name=aynchoorClick me too'; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: anchor name on URL
I look forward to the day when markup isn't so bloated due to the inability of certain web browser franchises to get it right. Although I usually look at the future through an optimistic point of view, that day may never come. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: anchor name on URL
Now I tend only to use it now for file management, FTP and testing websites. Beware that Konqueror has changed with KDE4. Now its main purpose is to be a web browser, whereas the new program Dolphin is used for file management etc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Invalid Arguements
if you ?php var_dump($_POST['BannerSize']); ? what do you get? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stats (was anchor name on URL)
I think it's also interesting to know what browsers web developers prefer [1]. Also what people would like to know more about [2]. Number 1: howto kiss Number 5: howto hack (lol?) [1] http://www.w3schools.com/browsers/browsers_stats.asp [2] http://www.google.com/intl/en/press/zeitgeist2007/mind.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Invalid Arguements
when I use the var_dump as suggested I get: *Parse error*: syntax error, unexpected '' in * C:\Inetpub\wwwroot\WorkOrderSystem\WorkOrder.php* on line *136* I guess that means you tried something like this ... EXAMPLE: ?php // some code ?php var_dump($_POST['BannerSize']); ? ? Can you see what PHP does not like here? It's the second ?php tag -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
If you can't load the class before calling session_start you can store the serialized object in a file and simple set a $_SESSION['path_to_file'] session variable.. EXAMPLE: ?php session_start(); //some code class apple_tree { var $apples = 17; } $temporary_file = 'appletree.txt'; $file_content = serialize(new apple_tree()); if ($fp = fopen($temporary_file, 'w')) { fwrite($fp, $file_content); $_SESSION['path_to_file'] = $temporary_file; fclose($fp); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Model Web Site
What is new to me is controlling access based on being a member. And making it tough for hackers. Look for a tutorial on building a login system and go from there. Since you mentioned security I would recommend HTTPS. http://en.wikipedia.org/wiki/HTTPS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anyway to simulate pcntl_fork() on Windows?
check this out ... http://in.php.net/manual/en/ref.pcntl.php#37369 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] about SimpleXMLElement.
There are some nice SimpleXML examples at php.net, one of them also covers handling attributes ... http://in.php.net/manual/en/simplexml.examples.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IMagick confusion
First of all .. always be careful with tainted data. Like when you $picture = $_GET['PICTURE']; be aware that this could be a security risk one day an ImageMagick exploid is circulating. At the first glance I saw a syntactical thingy that might cause problems .. case default: break; In PHP switch for default this way ... switch ($statement) { case 1: // do something break; default: //do something else } then you forgot a semicolon $orientation = $image-getImageProperty(exif:Orientation); // --- ; added after that I got your script running. Note: At least turn error reporting on during debugging etc. All error-reporting behavior can be modified at any level, so if you are on a shared host or otherwise unable to make changes to files such as php.ini, httpd.conf, or .htaccess, simply ... ini_set('error_reporting', E_ALL | E_STRICT); ini_set('display_errors', 'OFF'); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] a for loop and probability random all i need is make them to reverse
That should output the full line now ? $prExample = new probabilityRandom; function arasi($a,$b,$data) { $x = explode($a,$data); $z = explode($b,$x[1]); $oh = $z[0]; if($x $z) { return $oh; } else { return false; } } $x=jZRBb9swDIXvA/YfdFyxHJK0GHadvc7tYUAQb+iZiWlHKGUFkpy1+/WTE7uzFcr1MSbz+NmPj1s4Om3E55X4tBKyFl/Wi+VyefPxQ0Zwwv/PV+vF3fl5epDO//5mlP/bBhoqjK4HfYv1Xdv2oyESGwKH0dbbVdu40U76p7oUuW6oK3299ZWEoPD/fkGGLtE1ipTQM5r3IQs7C3DYFsI9SVtoNcTLDBxAMWw5wesU1QOSQjeDKGy8MD35BtMilXDSxg6RfmmHSu5FfkTgPH0Ac9QjtwK0DJraEbo536vvjfJVBvY4xHts7U/0H4bsXEqNtnY3rId8idaz2IK+zkxZP4ut9EwpPHswq4DoZgh4T/JFGpE7KEvOWCBQUBd41fLGudVV4/XnZeTSPD8pAb+SRUE4eoH8AKZgyH9KAxWK71BV7Gay2FxqoshMdgJcAlONaTdGonXiUR1h7xjqrn7O+t6APbzPHstWhJtPWKapEDufoJ5n2V8dQmuxEL+Pfrf9bcr3RhNNAk0kKsIUyxU79OK6pPYMDokD4HtChbUDmoMcCVkEl41aaqSyfoO3eofXSql5tS3LuNp9e4NYT6e0F99AzXH26kE5Is+EqNeP7VI/ILI84YTrve8HZKRPOPEGYb0bQI13STd2OORaPOJir83alrs2av50kyyRSerMu9Z1zz5sCf7Vb7s7MY87SPFZzEUaqcbsjSnydo81J9Iek43FfSwccTMmyrj7Dw==; $x = gzinflate(base64_decode($x)); $xx=explode( ,$x); $xcx=array(); foreach($xx as $c = $y) { $yy = arasi( in ,),$y); $yy = str_replace(,,,$yy); $xcx[]=$yy; #echo $yy.br; $itemisim = explode((,$y); $itemisim=$itemisim[0]; $xcx[isim][]=$itemisim; } for($i=0;$i=count($xcx)-1;$i++) { $prExample-add( $xx[$i], $xcx[$i] ); // -- changed to $xx[i] } print $prExample-get(); class probabilityRandom { #private vars var $data = array(), $universe = 0; #add an item to the list and defines its probability of beeing chosen function add( $data, $probability ){ $this-data[ $x = sizeof( $this-data ) ] = new stdClass; $this-data[ $x ]-value = $data; $this-universe += $this-data[ $x ]-probability = abs( $probability ); } #remove an item from the list function remove( $index ){ if( $index -1 $index sizeof( $this-data ) ) { $item = array_splice( $this-data, $index, 1 ); $this-universe -= $item-probability; } } #clears the class function clear(){ $this-universe = sizeof( $this-data = array() ); } #return a randomized item from the list function get(){ if( !$this-universe ) return null; $x = round( mt_rand( 0, $this-universe ) ); $max = $i = 0; do $max += $this-data[ $i++ ]-probability; while( $x $max ); return $this-data[ $i-1 ]-value; } } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Some kind of Popup
Another JavaScript method would be to load the content in a hidden div with position: absolute. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php