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 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: Click me Click me too HEREDOC; ?> BAD: Click me'; echo 'Click 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 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: ?> Can you see what PHP does not like here? It's the second "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 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 $y) { $yy = arasi(" in ",")",$y); $yy = str_replace(",","",$yy); $xcx[]=$yy; #echo $yy.""; $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
Re: [PHP] Re: Some kind of Popup
> One issue is I don't want to leave the space available on my regular web > page and would like to try not to overwrite something there - I'd rather > have a separate window of some sort that sort of floats over the web page. Well, since Javascript does the Job anyways you don't have to load it with the page when doing the div method. You would only need this little addition to your css .. .div_win { position: absolute; width: 400px; top: 100px; left: 10%; visibility: hidden; } When user initializes the request by clicking a link var div_window = document.createElement('div'); div_window.setAttribute('class', 'div_win'); div_window.className = 'div_win'; document.body.appendChild(div_window); Then you do some AJAX or JSON or whatever and apply it to the div. You can also move the div around doing it somehow like this ... http://www.quirksmode.org/js/dragdrop.html Still, opening up a new window might be the simple solution after all lol. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: İlgi: [PHP] a for loop and probability random all i need is make them to reverse
2008/11/22 Tontonq Tontonq <[EMAIL PROTECTED]>: > sorry i think i did tell u wrong about it problem is not showing name > of it as exaclty i just wanted give a point to it thats not real > problem real problem is i want it be more unpossible when i give the > class's add function's higher value In that case I would go for an algorithm using some kind of gaussian distribution, like the Marsaglia polar method [1]. I once wrote something similar to what (I think) you are asking for ... 1) { $u1 = 1/(rand(1, $likelihood)*$likelihood); $u2 = 1/(rand(1, $likelihood)*$likelihood); $v = $u1*$u1 + $u2*$u2; } $p = $u1*sqrt((-2)*(log($v)/$v)); return ($p < 0.85) ? 1 : (int)$p; } ?> The best return of this function would be 1. Now if you call the function with a high $likelihood (say 1000 and more) it gets less likely have 1 returned ( gaussian ). If you want to decrease the chance of getting values close to 1 then you will have to increase $likelihood inside the function or something. [1] http://en.wikipedia.org/wiki/Marsaglia_polar_method -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getStatic
> What would you do? I think PHP's string functions are pretty fast and even with large documents we are talking about a couple of extra microseconds on a modern machine. I once saw someone do pretty much the same as you are trying to do with strtr() [1], but I don't know if that function is faster than str_replace(). You should also consider that if you framework is going to manage someone's site one day then it could possibly be on a server with an older PHP version. I disagree with those on the list saying one should just stick to an existing templating framework, since it can be quite exciting to think some neat thingy out. Of course, most people (including me) hardly have any time at all to spend 1000s of hours on a more or less private project. [1] http://in.php.net/manual/en/function.strtr.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Voting methodology
I once had to implement something similar for a client's intranet page. First we designed it to work without login simply by logging the IPs (static and in the 10.10.*.* range) to avoid people voting twice or more. Then the client wanted to have some statistics like what department voted for what (yeah, not very democratic i know). So we changed it have the user log in before voting. Now we could also make sure that only authorized users were voting, unless a user forgot to log out and a delivery guy was taking his chances (very unlikely). I think the thingy about online voting is to ask oneself how serious the result has to be. Getting a 99% bulletproof result might be quite time consuming (thinking of HTTPS, tokens, authorization, etc. here). So it all depends on what your client wants. //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Happy Turkey Day
Today was a holiday? I looked "Thanksgiving" up and wikipedia said it's some kind of harvest festival. I guess that's why some mentioned turkeys .. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Short circuit evaluation and include
Hello everyone, I'm posting this as a warning when using include() or include_once() and checking their return values. I'm refactoring someone else's code at the moment and got a short circuit evaluation problem that made some problems .. Here's the code: FILE "some_file.php": some_method() ) return false; // line 14 return $obj; } $file = 'some_class.php'; some_function($file); ?> FILE "some_class.php": ERRORS PRODUCED: Warning: some_function(1) [function.some-function]: failed to open stream: No such file or directory in */some_file.php on line 14 Warning: some_function() [function.include]: Failed opening '1' for inclusion (include_path='.;*/php/pear/') in */some_file.php on line 14 Note: I ran this code in PHP 4.4.9 It seemed to me like include_once() was not fully executed or something when "short circuited", because this code worked just fine ... FILE "some_file.php": some_method() ) return false; return $obj; } $file = 'some_class.php'; var_dump(some_function($file)); ?> OUTPUT: object(some_class)(0) { } So I was wondering how include() or include_once() are actually being executed. I know they both return int(1) if no return specified in the included file. That's why I had a glance at the manual [1], where I saw this .. Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value. Example #4 Comparing return value of include So when I added the paranthesis it worked ... FILE "some_file.php": some_method() ) return false; return $obj; } $file = 'some_class.php'; var_dump(some_function($file)); ?> Me, after an hour of coding without a line of code. [1] http://in.php.net/manual/en/function.include.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to hide MySQL password in connection string in PHP script?
"Robert Dodier" robert_dodier AT yahoo.com wrote on 12-21-2003 > Hello, > > I am experimenting with a wiki system (PhpWiki) which uses > a MySQL database to store pages. It seems like a great system. > > The MySQL connection string is specified in a PHP script > in the form "mysql://FOO:[EMAIL PROTECTED]/baz". > > If I'm not mistaken the script has to be world-readable. > But then, can't any other user (logged in to the host) > just read the password? > > I share the host with other users, and the script has to > be in my home directory, so I don't think I can guarantee > that no other user can see it. > > Thanks for any advice, > > Robert Dodier I recently had the same problem on a shared host. The only solution I could think of was to have the server admin set an environment variable in an httpd.conf include file owned by root (chmod 600) [1]. EXAMPLE (mysql_pw.conf): SetEnv mysql_pw password SetEnv mysql_user username In PHP the variables then should end up in the $_SERVER array ... EXAMPLE (PHP): If this is impossible I can't think of another secure way on shared host systems, since other hosts usually are able to read your files. Maybe (if supported) one could SetEnv in .htaccess, so an attacker would at least have to glance into the PHP source code to find out where the password is stored. Still most people have it inside an include file and it works, I think. [1] http://httpd.apache.org/docs/1.3/mod/mod_env.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_intersect question
> The question is how to perform intersection on the following structure: > > $products = > array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow")); If I understood you correctly .. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing the 'media' attribute in php
> I have enough trouble getting my rather ancient brain around PHP, and > was hoping that I could avoid getting involved with JavaScript. > However it seems that it, or CSS, are the only possibilities for this > case. If I understood you correctly what you want is to change the style of the page when the user is printing it. As others mentioned before all you would have to do would be adding a second style sheet for that purpose. EXAMPLE: That would be all. Now if you want the user to have some kind of preview when clickin on a "print the page" button or link you need either JavaScript or PHP. The easiest way I could think of would be using the same print style sheet. For JavaScript have a look at this page ... http://www.quirksmode.org/dom/changess.html I think it should work in most modern browsers. Still doing it with PHP will work in every browser, but requires the page to reload ... For PHP have a look at this page ... http://www.maratz.com/blog/archives/2004/09/21/10-minutes-to-printer-friendly-page/#printQuery //A yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SELECT into array of arrays
> How should I proceed? Thanks in advance for any suggestions. Since you are looping through the result already, why not do it this way .. $combinedArray = array(); for ($i=0;$i 0) { while ($myrow = mysql_fetch_array($result)) { if (in_array($myrow['study'], $myArray)) $combinedArray[$myrow['study']][] = $myrow['symbol']; } } } You should get an array like this ... array("b2008" => array("A", "B", "C", "D"), "b2005" => array("A", "B", "E")) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SELECT into array of arrays
Correcting myself now .. $myArray = array('b2005', 'b2008'); $sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while ($myrow = mysql_fetch_array($result)) { if (in_array($myrow['study'], $myArray)) $combinedArray[$myrow['study']][] = $myrow['symbol']; } } Forgot to get rid of the first for loop -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adding key-> value pair to an array
> //for each row I want to add percentage as new key->value pair > // but it gives error 'Undefined variable: > percentage' >$row->$percentage = ($browseCount / $totalCount ) * 100; Obviously you get the error because $percentage is not defined .. I did not fully understand what you wanted. Here is a list of what should work ... #Set a variable percentage in $row $row->percentage = ($browseCount / $totalCount ) * 100; #Set a variable with name $percentage in $row $percentage = ($browseCount / $totalCount ) * 100; $row->$percentage = $percentage; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SELECT into array of arrays
And yet another thing i have overseen in my statement .. If you remove the first for loop, also change the sql query. But I'm sure you saw that already NEW QUERY: $sql = "SELECT study,symbol FROM test WHERE study IN ('".implode(', ', $myArray)."')"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adding key-> value pair to an array
> > //you can get really stupid with this.. > ${false} = 'some string here'; > echo ${''}; > //echos some string here > I like stupid things -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Poll of sorts: Javascript Form validation or PHP
Java Script should always be an option, unless you write the validation for yourself or people you personally know only. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Poll of sorts: Javascript Form validation or PHP
Nuclear power plants got the MCA [1] Developers got the MCA [2] [1] maximum credible accident [2] maximum credible addlebrained Both of them are what nobody likes to think of, but they can (and do?) happen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Poll of sorts: Javascript Form validation or PHP
> I put a small one together using regular expressions, > http://www.ashleysheridan.co.uk/coding_php_validation.php So we are "regexing" emails again? #OUT OF coding_php_validation.php COPY case 'email': { $expression = "/^([a-z0-9_\-\.]+)@([a-z0-9_\-\.]+)\.([a-z]{2,5})$/i"; $errorText = "The email does not appear to be a valid type."; break; } #END COPY 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] Ã(c)@℞.com
Re: [PHP] Poll of sorts: Javascript Form validation or PHP
I think hotmail, or was it some other mail mogul, is allowing their users to have those weird German umlauts and some accented characters. EXAMPLE: [EMAIL PROTECTED] We are living in a multilingual world with dozens of alphabets. Especiall those doing government sites should consider accessibility a must. I would not enjoy getting sued by some one who feels discriminated, because of denied access since his/her name contains "abnormal" characters. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A MySQL Question
Who says the big bang is past? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A MySQL Question
As a matter of fact, in space you can't even scream. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A MySQL Question
> Sure you can... I'm screaming right now... and I'm in space. A container > within a container within a container within a container (ad infinitum) > is still within the outermost container. I didn't hear you scream. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Chrome 1.0 released
I got so used to Opera's mouse gestures, now I can't work fluently with other browsers. So I tried Chrome for like 5 minutes. It's always like "How do I go back to the previous page again or how do I open a new tab?". As long as Chrome is not being bundled with new computers the average Windows users will stick to Internet Explorer. I know that from customers who are referring to IE as "the program on my computer's desktop running the internet". So if Google can manage to transform Chrome into the "internet program" M$ might be forced to make IE9 support Richard's HTML5 graphing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Chrome 1.0 released
I have to defend poor little IE a little now. It supports XHTML and CSS2 pretty well so far. And those standards came out a couple of months ago. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Chrome 1.0 released
It more and more seems like a conspiracy against M$ to me. A company trying to make up its own standards every once in a while, how can that be wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Read/decode barcodes from an image
Basic bar code detection is not that difficult. You set a couple of virtual lines over the images and "crawl" them pixel by pixel. Then you count the black/white changes and the density of each change. I could even think of doing this using GD if I had the time. On the other hand it can get pretty complicated if you need error correction like a neuronal network would provide it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What does
I think it can also be set in .htaccess php_flag short_open_tag off somebody confirm this or not. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching in a long text
What if the whole text has only 1 line? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help on caching an object.
Hello gang, First of all, yes I searched the mailing list's archive. My problem is very simple: I have an object that's definately called with every page request. It's pretty much the same for every unregistered/anonymous user. And it's not small. Alot of attributes are being set from DB queries etc. Now my idea was to do some sort of caching with PHP to speed things up. So I was wondering if anybody had experiences on this ... Of course, I considered using serialize(), but it seemed to me as if it could cause even more lagging since PHP requires the class to unserialize the object correctly. Then I would end up reading the class file, reading the searialized object and unserializing it. A 100 simple DB queries might be done in the same time or at least not much slower. Could it be that I'm looking at the wrong place? Should it be more like caching the queries or something similar? Thank you very much for everyone's effort in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can an elephant count for nothing?
> Can anyone explain clearly why comparing a string > with zero gives this apparently anomalous result? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can an elephant count for nothing?
I guess the main reason for PHP to behave like this is to make life easier for many everyday situations. EXAMPLE: User input via GET or POST - usually string You compare it to some value - int/string or whatever So if a user posts '17' (string) and you compare it to 17 (int), unless you are using ===, PHP won't complain. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] anyone interested in PHP? Call for moderator
It is good to hear that they teach PHP in kindergarden these days. //Yeti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question regarding OO
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: 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 > >> > >> >> > >> /*** 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?
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 ''..'' 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**ámplè** stríng wíth áccénts.* *This is an ex**ample** 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'); >> >>
[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: 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 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: > >> > #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
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 ..* ?> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> http://www.w3.org/1999/xhtml";> test You submitted characters (STRLEN). You submitted characters (MB_STRLEN). Characters Left:2048 œŸŒ‡Ņ MB_STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds'; $s_t = microtime(); strlen('œŸŒ‡Ņ'); $e_t = microtime(); echo 'STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds'; *# So much for internationalisation. # Just writing this as a reminder for everyone who is facing similar situations.* ?>
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? MB_STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' milliseconds'; $s_t = microtime(true); foreach ($mb_array as $mb_string) { strlen('œŸŒ‡Ņ'); } $e_t = microtime(true); echo 'STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' milliseconds'; ?> 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: > > > *# 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 ..* > > ?> > > > http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> > > http://www.w3.org/1999/xhtml";> > > > > > > test > > > > > > You submitted characters (STRLEN). > > You submitted characters (MB_STRLEN). > > Characters Left:2048 > > > > > onchange="check_length();" rows="10" cols="50">œŸŒ‡Ņ > > > onclick="submit_form();" /> > > > > > > <!-- > > 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; > > } > > --> > > > > > *# 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 'MB_STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds'; > > $s_t = microtime(); > > strlen('œŸŒ‡Ņ'); > > $e_t = microtime(); > > echo 'STRLEN took : '.(($e_t - $s_t)*1000).' milliseconds'; > > > > *# So much for internationalisation. > > # Just writing this as a reminder for everyone who is facing similar > > situations.* > > ?> > > > > > > > > You can't determine timing by simply calling each function one time. I > changed your script to the following: > > > $iterations = 1; > > $s_t = microtime(true); > for ($i = 0; $i < $iterations; ++$i) { > mb_strlen('œŸŒ‡Ņ', 'UTF-8'); > } > $e_t = microtime(true); > echo 'MB_STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' > milliseconds'; > > $s_t = microtime(true); > for ($i = 0; $i < $iterations; ++$i) { >strlen('œŸŒ‡Ņ'); > } > $e_t = microtime(true); > echo 'STRLEN took : '.(($e_t - $s_t)*1000/$iterations).' > milliseconds'; > > ?> > > I ran this script several times, and the results below are fairly typical: > > MB_STRLEN took : 0.054733037948608 milliseconds > > STRLEN took : 0.037568092346191 milliseconds > > > The multi-byte function is slower, but not even by a factor of 2 on my > development machine. > > Andrew >
Re: [PHP] Not found 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
$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 ü. 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 ü in your textarea into the namespace-proper "ü". You could try using htmlentities to convert the & into & 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
blah blahblah blah'; var_dump(explode('', $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=$1&getparam2=$2 RewriteRule ^blog[/]{0,}([^/]{0,})[/]{0,}([^/]{0,})[/]{0,}.*$ blog.php?getparam1=$1&getparam2=$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 ## ## test.php ## http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> http://www.w3.org/1999/xhtml";> Referrer Test Page alert('Referrer ('+(typeof document.referrer)+'['+document.referrer.length+']): '+document.referrer); Referred page Referring page: $page REFERRER; ?> # 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=$1&getparam2=$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 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 .. 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 Only set if there is a $_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: 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-general&m=122383066714789&w=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-general&m=121926660406116&w=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