Re: [PHP] Could someone tell me what a tilde(~) in PHP does ?
On Tue, Apr 8, 2008 at 6:19 AM, Tony Collings [EMAIL PROTECTED] wrote: The humble tilde (~). I came across it the other day in some PHP code [code]~E_ERROR[/code] That comes from C, not postpositional math. It's bitwise negation. That is, the number 47 in binary is 110001, with leading 0's out to whatever the word size is, usually 32 or 64 bits. The ~ flips the bits, so on a 32-bit system ~47 is binary 11001110, which is -48 if you treat it as a signed value and 429496248 as unsigned. The tilde is most often seen in the company of flag values, where each bit represents an option that is on or off. Typically, you have a bunch of constants defined as the individual bit values, like say E_DEBUG. Then ~E_DEBUG means turn on everything except E_DEBUG. Often used with bitwise AND () as a mask to turn a particular bit off, as in ?php $flags = ~E_DEBUG ? which turns off E_DEBUG while leaving the other bits in $flag unchanged. -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could someone tell me what a tilde(~) in PHP does ?
On Tue, Apr 8, 2008 at 8:50 AM, Mark J. Reed [EMAIL PROTECTED] wrote: That is, the number 47 in binary is 110001, ... or 10, if you want to be technical. 110001 is 49. :) The important thing is to understand what you're doing, rather than to get the right answer. --Tom Lehrer -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] joins issues again
On Tue, Apr 8, 2008 at 7:28 AM, Steven Macintyre [EMAIL PROTECTED] wrote: I have the following SQL statement; ... and this relates to PHP how? SELECT count( salesID ) AS count, branch_name, company_name, branch.branchID That doesn't make sense. You're selecting a group function (COUNT) along with other columns which you're not grouping on. It might help if you told us what you were trying to accomplish with the query. But you'd be better off asking on a SQL list instead of a PHP one. FROM sales LEFT JOIN IGuser ON sales.IGuid = IGuser.IGuid LEFT JOIN branch ON IGuser.branchID = branch.branchID LEFT JOIN company ON branch.companyID = '{$companyID}' WHERE maincompanyid = '{$mcid}' GROUP BY branch.branchID ORDER BY branch_name ASC However, i do not want those join records to be appended, only to return the count of records from sales. So why are you joining in the first place? -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string
On Mon, Apr 7, 2008 at 9:30 AM, [EMAIL PROTECTED] wrote: Do a preg match to find one or preg_match_all to find all the john in the string. preg_* is overkill if you're just searching for a literal string. use it if you're searching for any strings matching a pattern, part of which you don't know. If you know the entire string you're looking for, strstr() is both more efficient and easier to use. Now, strpos() is more efficient still, but arguably more annoying to use because of the 0 but true issue that necessitates checking for !== false. Besides efficiency, the only difference between strstr() and strpos() is what they return. strpos() returns the index of the first match, while strstr() returns the entire string starting from that point; it's the building of the copy of the string that causes strstr() to be less efficient. Both functions have case-insensitive variants stristr and stripos. In each case, if the substring occurs more than once within the outer string, the return value is based on the *first* occurrence. strpos() (but not strstr()) has a variant that uses the *last* one instead: strrpos() (r=reverse), which also has a case-insensitive version strripos(). You can easily define a strrstr() though: function strrstr($where, $what) { $pos = strrpos($where, $what); return $pos === false ? false : substr($where, $pos); } And for good measure, a strristr: function strristr($where, $what) { $pos = strripos($where, $what); return $pos === false ? false : substr($where, $pos); } ?php $name = John Taylor; $pattern = '/^John/'; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); print_r($matches); ? $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- 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 -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date comparison Question
On Mon, Apr 7, 2008 at 11:42 AM, [EMAIL PROTECTED] wrote: t the data is fed from the database, CaldTime is timestamp and since it will not allow me to have 2 timestamps in the same table ?? What database are you using? It sounds like it has a specific meaning of timestamp - probably the last time this row was modified - and you want an arbitrary date column, which would probably be a different column type. Not a string, though. An actual date type. possible names are date, datetime, datestamp... , and you I set the CallEnd varchar(12). Storing the data they seem to be the same for output. I checked hexadecimal and binary to look for obscurities. $sqldata['CaldTime'] = 2008-04-07 11:15:32; $sqldata['CallEnd'] = 2008-04-07 11:17:17; $time1 = strtotime($sqldata[CaldTime]); $time2 = strtotime($sqldata[CallEnd]); $interval = $time2 - $time1; echo $interval; +++ Displays like 1.75:0 I am looking for a more precise time like 1:45 instead. Am I looking at this all wrong for time difference? strtotime returns an integer number of seconds. The difference between $time1 and $time2 is 105. If you want minutes and seconds, you have to do the math yourself. $interval_min = floor($interval/60); $interval_sec = $interval % 60; echo $interval_min:$interval_sec; -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arbitrary mathematical relations, not just hashes
As far as languages with two-way relation go, there are many; perhaps the most prototypical is Lisp, in that either member of a pair within an alist can be used to look the pair up, with no extra function or second map definition required. But PHP has pretty good support, too, actually. If you have a 1-to-1 relation, you can use array_flip() to get a second array with the keys and values swapped in one go. If you have a 1-to-many, as in this case, you can use the optional search parameter to array_keys: $color = array('apple' = 'red', 'ruby' = 'red', 'banana' = 'yellow'); array_keys($color, 'red') Array ( [0] = apple [1] = ruby ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arbitrary mathematical relations, not just hashes
On Sun, Apr 6, 2008 at 11:51 PM, Casey [EMAIL PROTECTED] wrote: I hit reply-all... now am I suddenly subscribed to Perl and Ruby lists!?! Huh, didn't notice the cross-posting. But no, you're not subscribed to any new lists. Since we're cross-posting, the translation of my sample would be apropos. Here are a few different takes on a loopless versions in Ruby. Given: color = { :apple = :red, :ruby = :red, :banana = :yellow } This is, I think, the most straightforward: color.keys.find_all { |k| color[k] == :red } But having to repeat the hash name is inelegant. Which leads us to this: color.find_all { |k,v| v == :red }.collect { |p| p[0] } Building up a list from the elements of a Hash would seem to be a natural application of Hash#inject, although the fact that the inject block has to return the accumulator makes it a little less elegant than it could be, IMO: color.inject([]) { |a,p| a p[0] if p[1] == :red; a } In Perl5 I don't have a better solution than the first one above: my %color = ( apple = 'red', ruby = 'red', banana = 'yellow'); grep { $color{$_} eq 'red' } keys %color; -- Mark J. Reed [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php