[PHP] Re: Making verification code harder to OCR?
There was a thread about something similar to this on Slashdot oh, at least a year ago. One technique that was suggested was to draw a random image on the screen - say, a grid of colored squares, or a set of different shapes/images - and just direct people to 'pick the blue square' or 'click on the large house' or something to finish the registration. Of course, there are limits here for the color blind or those using text browsers/screen readers... As an alternative, if you needed to stick with text fonts, you could use some unusual-looking ones, like old english, or a 3-d looking one, perhaps combined with the color technique below. -steve At 8:09 AM +0100 11/26/02, Derick Rethans <[EMAIL PROTECTED]> wrote: Leif K-Brooks wrote: I'm using a verification code image to stop automated sign ups, but two hackers seem to be OCRing it. I've looked through the registration script, and there's definitley no security holes. Does anyone have any ideas as to making the image harder to OCR? Use two different shades of one color (ie. blue and somewhat lighter blue). You may also want to do some tricks with the form of the characters, so instead having a nice "0" on your screen, you can use dots to somewhat represent it. (Much like the color-blindness tests do). regards, Derick // seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 10); } $seed = make_seed(); mt_srand($seed); $dbh = mysql_connect ("", "", "") or exit; mysql_select_db ("",$dbh) or exit; $authimage = ImageCreate(40,15); $bgnum = mt_rand(1,3); switch($bgnum){ case 1: $white = ImageColorAllocate($authimage, mt_rand(250,255), mt_rand(250,255), mt_rand(250,255)); break; case 2: $green = ImageColorAllocate($authimage, mt_rand(0,5), mt_rand(250,255), mt_rand(0,5)); break; case 3: $yellow = ImageColorAllocate($authimage, mt_rand(250,255), mt_rand(250,255), mt_rand(0,5)); break; } $black = ImageColorAllocate($authimage, mt_rand(0,30), 0, 0); header("Content-type: image/png"); $getcode = mysql_fetch_array(mysql_query("select * from signupcodes where id = '$id'")); imagestring($authimage,mt_rand(4,5),mt_rand(0,5),0,$getcode['code'],$black); imageline($authimage,0,mt_rand(0,15),40,mt_rand(0,15),$black); imageline($authimage,0,mt_rand(0,15),40,mt_rand(0,15),$black); imagepng($authimage); imagedestroy($authimage); ?> -- - Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mmmmm SELECT
At 04:27 PM 1/6/03 , Bruce Levick wrote: I have this silly problem. This select query works fine. $query_retrievetasks = "SELECT * FROM tasks, users WHERE tasks.UID = users.User_id ORDER by tasks.ID"; But when I add a further filter (AND active="yes") it comes up blank...currently all the active rows in the tasks table are equal to "yes" so they should still display, but comes up with a blank. $query_retrievetasks = "SELECT * FROM tasks, users WHERE tasks.UID = users.User_id AND active="yes" ORDER by tasks.ID"; Can't understand this, is it just something simple I am missing?? If this is the query you are actually using, it is causing a PHP syntax error due to the nested double-quotes. Use $query_retrievetasks = "SELECT * FROM tasks, users WHERE tasks.UID = users.User_id AND active='yes' ORDER by tasks.ID"; Note the single-quotes around 'yes'. I'm guessing your installation is set up to not echo PHP errormessages back to the screen, that's why you didn't see an error message. -steve ++ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] get the $email string
At 5:04 PM + 1/16/03, Miguel Br·s wrote: Hi, i made a page to display some user details and then clicking on the user name it goes to another page to send a mail via mail() function. here is the line of the first page name; ?> when click on user name, it goes to the mail_active.php?[EMAIL PROTECTED] on the mail_active.php page, how do I get the e-mail address to send? I mean, the mail function is mail ("$to","$subject","$message","From: $sender"); How can I take the $to string to be [EMAIL PROTECTED]? IN this case you could use mail ($_GET['email'],"$subject","$message","From:$sender"); or mail ($_REQUEST['email'],"$subject","$message","From:$sender"); See http://www.php.net/manual/en/language.variables.external.php for more information on variable handling. Also keep in mind that the script as you've shown it is looks very insecure; anybody, including joe-spammer, could send mails to people simply by calling your URL http://your.domain/mail_active.php?[EMAIL PROTECTED] It's best to pass some sort of obscure ID instead of the data. I would check out the use of sessions here: http://www.php.net/manual/en/ref.session.php -steve -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Number Sign in String Variables
You need to urlencode() selectively; in this case, only the short_desc needs to be encoded, so you would have a statement something like echo "add_to_cart.php?item_num=$item_num&quantity=$quantity". "&sale_price=$sale_price&unit=$unit&short_desc=". url_encode($short_desc)."&wholesaler=$wholesaler&cost=$cost" ; You need to encode any parameter (everything to the right of that first '?') that might include the '?', '&'. '#' or space characters, since those all mean something special in a URL. To be safe, it's best to encode everything - or at least all strings. However, you have to encode them individually, since you need the UNencoded '&' between them to delimit parameters, and you need that '?' there to indicate the start of the parameters. I don't know the details of your program design, but there may be no reason to pass all the item details (description, sale price, etc.) in the URL anyway. Can't you just look them up in the add_to_card.php page, based on the item_num? Thus, all you need to pass are the quantity & item_number: echo "add_to_cart.php?item_num=$item_num&quantity=$quantity"; For one thing, that would eliminated the possibility of someone trying to get everything for free by manually typing a URL like add_to_cart.php?item_num=SOU3432410&quantity=1&sale_price=0&unit=... -steve At 6:29 PM -0500 1/18/03, Joab Stieglitz wrote: OK. I urlencoded the URL and now the URL passes correctly... add_to_cart.php%3Fitem_num%3DSTT32700%26quantity%3D1%26sale_price%3D52.78%26 unit%3DBX%26short_desc%3DENVELOPE%2C100%25COT%2024%23%2CGY%26wholesaler%3DUS %26cost%3D37.700 ... but I get the following error: Forbidden You don't have permission to access /carmae/add_to_cart.php?item_num=STT32700&quantity=1&sale_price=52.78&unit=B X&short_desc=ENVELOPE,100%COT 24#,GY&wholesaler=US&cost=37.700 on this server. I've never seen anything like this before. Suggestions? "Brad Pauly" <[EMAIL PROTECTED]> wrote in message 1042912825.15063.33.camel@earth">news:1042912825.15063.33.camel@earth... > For example, this URL: > > > add_to_cart.php?item_num=SOU3432410&quantity=1&sale_price=24.92&unit=BX > > &short_desc=ENVELOPE,25%COT 24#,IY&wholesaler=US&cost=18.690 > > gets cut off at the # sign, so $wholesaler and $cost come out empty. > > Any suggestions to get around this? You could use urlencode() and urldecode(). http://www.php.net/manual/en/function.urlencode.php http://www.php.net/manual/en/function.urldecode.php Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Word Count
To be somewhat more rigorous, you could do: $numOfWords = count(preg_split('/\s+/', trim($string))); (also untested); this ignores leading/trailing whitespace, and deals with multiple spaces/tabs between words. There is an example in the docs (below) called 'Get the parts of a search string' that shows how to add other characters that you might consider valid word delimiters - eg, a comma. See http://php.he.net/manual/en/function.preg-split.php -steve At 10:41 AM -0600 1/23/03, "Chris Boget" <[EMAIL PROTECTED]> wrote: > Is there a way to count the number of words in a string? Untested, but this should work. $string = "Is there a way to count the number of words in a string?" $numOfWords = count( explode( " ", $string )); Chris -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing help
Or (untested): $String = 'NORTH LITTLE ROCK AR 72118-5227'; $Bits = split(strrev($String), '[[:space:]]+', 3); $Zip = strrev($Bits[0]); $State = strrev($Bits[1]); $City = strrev($Bits[2]); ...could also use preg_split() - steve At 4:44 PM -0400 8/20/03, "CPT John W. Holmes" <[EMAIL PROTECTED]> wrote: From: "Jonatan Pugliese." <[EMAIL PROTECTED]> From: "Matt Matijevich" <[EMAIL PROTECTED]> > I have have a string that I need to split into 3 different variables: > City,State, and Zip. Here is a couple examples of the strings I need to > parse: > > ANCHORAGE AK 99507-6420 > JUNEAU AK 99801 > > NORTH LITTLE ROCK AR 72118-5227 > > Does anyone have an idea how I could slit this into the appropriate > variables, maybe some kind of regular expression? I cant use the space > character to split the data because some of the city names have spaces > in them. $vector=split( " ", $string, ); $City=$vector[0]; $State=$vector[1]; $Zip=$vector[2]: Umm, no. then you'll have $City = "North", $State = "Little" and $Zip = "Rock" with the last example. The following works: $str = "NORTH LITTLE ROCK AR 72118-5227 JUNEAU AK 99801 ANCHORAGE AK 99507-6420 NORTH CARO MI 48732 "; preg_match_all('/^(.*)([a-z]{2})\s+([0-9]{5}(-[0-9]{4})?)/im',$str,$matches) ; $count = count($matches[1]); echo $count . ' addresses found:'; for($x=0;$x<$count;$x++) { $city = trim($matches[1][$x]); $state = trim($matches[2][$x]); $zip = trim($matches[3][$x]); echo "City: $city, State: $state, ZIP: $zip"; } ?> ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | [EMAIL PROTECTED]: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] chill out
Well, you could do what the sunmanagers mailing list does...every so often (every month? every other month?) a 95KB FAQ is sent to all subscribers. However, the main problem is getting people to READ it. And those people likely to read it are probably the same people who'd do the requisite documentation/web search first anyway. I suppose you could set it up so that only new subscribers got the FAQ. Or if you want to be really ambitious/annoying, new subscribers would get the FAQ, then - to activate them on the mailing list - they'd have to take a short web-based quiz on the contents of the FAQ before they are allowed to post. However, as others have said, the signal-to-noise ratio of this list is pretty high, easiest thing is just to tolerate/ignore the inappropriate questions... -steve At 2:21 PM +0500 4/4/03, Haseeb Iqbal wrote: hi all, just like to add something here, (which i recmended before) there should be a automated way to email all the new users about what php is, that explain them that php is server side and it can't do client side, just a plain email will do this will certinaly minimize the no of off topic posts,what you people think? i think it will help Friendship is always a sweet responsibility, never an opportunity. HaSeEb IqBaL. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | [EMAIL PROTECTED]: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disturbing parsing problems
At 12:19 PM -0400 7/29/02, <[EMAIL PROTECTED]> wrote: > I added a few number_format() statements to previously working code (not >having changed any {}s ) and it started getting parse errors, 'unexpected >t_if, expected t_while'. In other words, it thinks the do statement shown >below has been closed, and wants to hear about the while part. > > I checked over the sets of braces about 10 times, but the only way to >fix it ended up being to have an uneven number of braces - two close braces >needed eliminating. I'm not going to post all the code unless it's >necessary but here is the basic control structure. I've shown here what >braces I commented out. All of the below is escaped in and out of HTML many >times. > > PHP 4.2.2 on Windows 2000 Professional. Is this a bug, or have people >experienced weird problems with braces before? > >Regards, >Colin Teubner > >if (){ > do { > if (){ > while () {} > if () ; > else if (); > else ; > } I assume you mean if () : else if (): else : here (colon instead of semicolon)? AFAIK PHP doesn't allow the alternative syntax - http://php.he.net/manual/en/control-structures.alternative-syntax.php - with semicolons. Or do you really mean if () {} else if () {} else {} If you are using the alternative syntax, I recall several messages about people having problems nesting both forms of syntax. Try using all one style or the other. Lastly, quadruple check that you haven't accidentally quoted or double-quoted a { or ( or something that you THOUGHT was part of PHP code; syntax highlighting editors can definitely help here. -steve > if () {} > if () { > if { > } > // } > if () { > if { > } > // } > } while (); > if() {} //(4x) >} > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Vars passed via URL disappearing
At 3:29 PM -0400 8/2/02, Monty wrote: >I just upgraded to PHP 4.2.2 and am trying to make my sites work with >register_globals turned OFF. I notice, however, that with register_globals >turned off any variables I pass via the URL don't seem to be recognized by >the script it was passed to. > >So, if I pass "http://my.site.com/page.php?id=2002";, the variable "id" is >empty when I try to access it in page.php ... > >if (!empty($id)) { do stuff...} >else { echo "error"; } > >With register_globals OFF, the above produces the error message. With >register_globals ON, it works fine. > >I thought register_globals only affected session, cookie and get type >variables? Why is PHP ignoring the variables passed via the URL? 'variables passed via the URL' = 'GET variables' -steve -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Open 10 http connections in parallel
I've never done this before, but you probably could open these connections via a socket, and set them all non-blocking. Presumably you'd them have to write a loop that polled all connections to check if they'd closed, or time them out after some number of seconds. See http://php.he.net/manual/en/function.socket-set-blocking.php and http://php.he.net/manual/en/ref.network.php -steve At 1:28 PM +1000 8/9/02, Martin Towell <[EMAIL PROTECTED]> wrote: >use C and fork() >php (AFAIK) can't do parallel programming > >-Original Message- >From: NoWhErEMan [mailto:[EMAIL PROTECTED]] >Sent: Friday, August 09, 2002 12:58 PM >To: [EMAIL PROTECTED] >Subject: [PHP] Open 10 http connections in parallel > > >Hello, > >I had to write a script to open 10 http connections for different links and >get the response from the host. >I do it by fopen each url one by one and save the response to a separated >file. But it slow! >I wonder if i can open 10 connnect (or more) in parallel? > >Thanks in advance. >NoWhErEMaN > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Average Number For Math Functions
At 05:55 PM 8/29/02 , JohnP wrote: >Ok I looked at all the math functions for PHP but saw no way of returning >the average of a set of numbers - I plan on using this for a rating system >- any help? > >-- >John Nope - you'll have to 'roll your own' by looping though the set, or (if you have version >= 4.0.5) you can use array_reduce() in conjunction with the count() function. If these values are coming from a database, most databases have aggregate functions to do sums, averages, etc. -steve +----+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] request what a user clicked
At 03:12 PM 8/30/02 , stu9820 wrote: >what is php's request object? >like in ASP - Request("variable") Short answer: $_REQUEST['variable'] (for PHP version >= 4.1.0) Long answer: http://www.php.net/manual/en/language.variables.external.php -steve >Jeff >UWG Student >[EMAIL PROTECTED] +--------+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] whitespace...
At 04:37 PM 9/4/02 , Matt Zur wrote: >How do I remove the whitespace from a document? I consulted the manual and >it said to use the trim function. But in a large PHP document, with lots >of fuctions etc in PHP... is there a simple way to compress the whitespace >of the entire document? Rather than going through each var and using the >trim? Like add a header at the top: > > >If you have a 300k php document, won't the source code reveal (after the >browser displays the page) a bunch of whitespace. Doesn't this add to dl >time and if so, how do I get rid of it. Not 100% sure if I understand the drift of your question, but here's a few possibilities. (1) Are you concerned about whitespace you put in a PHP program to enhance readability slowing down page loads? Any whitespace WITHIN PHP tags does not get sent to the browser at all. So you don't need to worry about it. (2) Are you concerned that the OUTPUT of your PHP program and/or HTML embedded therein might have excessive whitespace? If so, you could create an output handler that cleans up the output before sending, I think; see http://www.php.net/manual/en/ref.outcontrol.php Or, use compression. See: http://www.php.net/manual/en/function.ob-gzhandler.php (3) If you simply wanted to clean up excessive whitespace in a file, you could use a snippet like: ...read file into $file variable # Replace multiple spaces/tabs with a space $file = preg_replace('/[ \t]{2,}/','/ /', $file); # Replace multiple lines with single line $file = preg_replace('/(\n|\r|\r\n){2,}/', '\r', $file); ...write $file back out That last line for replacing multiple blank lines is probably wrong; at the very least you'd have to do some platform checking (Win vs. Mac vs. Unix) to get the proper line ending. You might also be able to use the pattern '/(^$){2,}/m' In PHP4 I think you can use arrays: ...read in $file = preg_replace( array('/[ \t]{2,}/', '/(\n|\r|\r\n){2,}/'), array('/ /', '\r'), $file ); ...write out See http://www.php.net/manual/en/function.preg-replace.php http://www.php.net/manual/en/pcre.pattern.syntax.php http://www.php.net/manual/en/pcre.pattern.modifiers.php -steve ++ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] PHP and Apache
It's certainly _possible_ - Your httpd.conf (I'm assuming you use Apache, of course) file is just a text file that can be read/written like anything else. Then you could do a system('/path/to/apache/bin/apachectl restart'); to activate. Doing it this simply, thoughm means that your webserver's user (usually nobody) would have write access to the conf file and execute perms to apachectl, which could open up some bulldozer-security holes. At the very least, you want to access things through SSL. But you might want to try Webmin: http://www.webmin.com/ Looks very comprehensive, and I've seem a number of good recommendations for it. I've been planning on doing a little testing of it on my test server, but haven't had the time. -steve At 4:48 PM +0100 9/6/02, Tim Haynes wrote: >Is there any easy way of creating,editing and deleting virtual hosts using >PHP via a website?? I have already thought of a way but seems a little long >winded. > >Thanks in advance. -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need more memory... possible to set?
Several ways: (1) PHP still reads a php.ini file, so you could set it there; try a php -i | grep php.ini to find out where the commandline php thinks it is (and/or do php -i | grep memory_limit to find the default memory limit setting. (2) You can set it at execution time via the -d command option: php -d memory_limit=20M -f yourprogram.php (3) Set it in your program with the ini_set() command: http://php.he.net/manual/en/function.ini-set.php -steve At 11:29 PM -0500 9/9/02, Damian Harouff wrote: >Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to >allocate 53738 bytes) in /var/cli/mp3anal/mp3anal.php on line 68. >Segmentation fault > >This is line 68: while ($found = fscanf ($fp, "%s - - >[%[A-Za-z0-9/]:%[0-9:] %[+-0-9]] \"%[A-Z-] %s %[A-Z0-9/.]\" %[0-9-] >%[0-9-]\n", >&$ip, &$date, &$time, &$ofset, &$request, &$file, &$protocol, >&$code, &$bytes)) { > >Since this is a command line program, is it possible to set the memory >allocation higher? It's a program to read the mp3 lines out of an apache >log file. > >This is the entire program: >http://www.cekkent.net/upload/mp3anal/mp3anal.phps > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression
As someone else mentioned, filenames with embedded spaces can be confusing and should be avoided where possible (in the future, I'd replace the space with an underscore _). However, the following will do what you want (untested): $regs = preg_split('/\w+/', $dirline, 9); $regs[8] will contain the filename, even if it has spaces. Explanation: the regex splits the line on strings of whitespace (spaces, tabs, etc.), for a maximum of 9 elements. Since $regs[8], containing the filename, is the ninth element, the rest of the line is dumped into that element without further regex processing. Since the spacing pattern remains the same from a unix ls -l command no matter what the file size or date is, you should be ok. See http://php.he.net/manual/en/function.preg-split.php for more info. Also, if you are doing something like $output = `ls -l`; and then parsing the output you may want to investigate PHP's file/directory functions instead: http://php.he.net/manual/en/ref.dir.php http://php.he.net/manual/en/ref.filesystem.php -steve At 10:33 PM -0800 11/6/02, Salman wrote: Hi, I have this ereg call ereg("([-d])[rwxst-]{9}.* [0-9]* [a-zA-Z]+ [0-9: ]* (.+)",$dirline,$regs); This regular expressions parses the following line: drwxrwxrwx 1 ownergroup 0 Nov 5 23:19 fantasy to return: fantasy (or in general any filename/directory name) The above regular expression works fine in every except when the filename is something like this: drwxrwxrwx 1 ownergroup 0 Nov 5 23:19 6 fantasy Notice in this case the filename is "6 fantasy" however $regs[1] returns only: "fantasy" Can anyone help me to fix this problem. Thanks a bunch -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP and MySQL sorting using COUNT
Actually, using your original query and referring to $row['count(*)'] would work too. However, when using calculated fields I always use a column alias as Rich recommends - it makes things a lot clearer. -steve At 1:54 PM + 11/13/02, "Rich Gray" <[EMAIL PROTECTED]> wrote: try '... ,count(*) as count ...' then you should be able to reference it as $row['count'] HTH Rich -Original Message- From: [EMAIL PROTECTED] [mailto:ed@;home.homes2see.com] Sent: 13 November 2002 13:44 To: [EMAIL PROTECTED] Subject: [PHP] PHP and MySQL sorting using COUNT I'm sorting records using COUNT with the following mysql command $result = mysql_query ("SELECT company_name, agent_name, count(*) FROM $cur_listings GROUP BY company_name, agent_name"); Running this in MySQL does exactly what I need it to do but how do I echo the COUNT portion of the array? I know the company_name would be $row['company_name'] and agent_name is $row['agent_name']; Thanks, Ed Curtis -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql/php large integer query oddity
I have a query oddity that looks like an integer overflow, but it shouldn't be. Excerpt from my program: #DEBUG echo "\n$Query\n"; #DEBUG $hResult = _do_query(__LINE__, $Query); # _do_query() simply executes mysql_query, and does nice error formatting if necessary $First = true; while ($Row = @mysql_fetch_array($hResult)) { if ($First) { $First = false; show_table_open($Myself); } echo '', '', $Row['source_code'], '', '', $Row['chromo_code'], '', '', $Row['type'], '', '', number_format($Row['min_exon_length']), '', '', number_format($Row['max_exon_length']), '', # '', $Row['min_exon_length'], '', # '', $Row['max_exon_length'], '', "\n"; } This produces the output select sm.source_code,chromo_code,type,min(end_coord-start_coord+1) as min_exon_length,max(end_coord-start_coord+1) as max_exon_length from source_master sm left join chromosome_master chm using (source_code) left join contig_master cm on (cm.chromosome_id=chm._id) left join contig_position cp on (cp.contig_id=cm._id) group by chromosome_id,type order by sm.source_code,chromo_code,type Source Chromosome Type Min_exon_length Max_exon_length tigr 1 pseudogene 59 14,623 tigr 1 TIGR: unspecified type -20,699,646 29,780,051 tigr 2 pseudogene 248,789 tigr 2 TIGR: unspecified type -18,834,528 16,190,138 tigr 3 pseudogene 39,302 tigr 3 TIGR: unspecified type -23,058,902 14,292,141 tigr 4 pseudogene 248,949 tigr 4 TIGR: unspecified type -9,199,9049,000,303 tigr 5 pseudogene 12 14,463 tigr 5 TIGR: unspecified type -14,334,542 26,344,478 HOWEVER, if I cut & paste the echoed query to the mysql commandline, I get: +-+-++-+-+ | source_code | chromo_code | type | min_exon_length | max_exon_length | +-+-++-+-+ | tigr| 1 | pseudogene | 59 | 14623 | | tigr| 1 | TIGR: unspecified type | 2 |29780051 | | tigr| 2 | pseudogene | 24 |8789 | | tigr| 2 | TIGR: unspecified type | 2 |18834530 | | tigr| 3 | pseudogene | 3 |9302 | | tigr| 3 | TIGR: unspecified type | 1 |23058904 | | tigr| 4 | pseudogene | 24 |8949 | | tigr| 4 | TIGR: unspecified type | 2 | 9199906 | | tigr| 5 | pseudogene | 12 | 14463 | | tigr| 5 | TIGR: unspecified type | 2 |26344478 | +-+-++-+-+ 75 rows in set (9.15 sec) Notice that I get bizarre results on min_exon_length for the 'unspecified type' lines; in addition, the max_exon_length is off 3 of the 5 times. All of the other 75 rows are identical. Is there some setting in my.cnf or php.ini that I need to check - perhaps mysql_always_return_correct_results? I tried echoing the results out directly instead of using number_format(), but there was no change in the numbers. I've never seen anything like this...perhaps I need more coffee? Versions: Apache 1.3.26/php 4.1.2, using mysql client API 3.23.47 MySQL 3.23.47-log Platform: SunOS 5.8 sun4u sparc SUNW,Sun-Fire-280R Thanks in advance, steve -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | SETI@Home: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] NEVERMIND: mysql/php large integer query oddity
Boy do I REALLY need some coffee...one query was on the production database, the other was on the development copy. I suppose I should set the programmer_first_check_database_parameter_you_idiot setting in php.ini... Sorry for consuming unnecessary list space. -steve I have a query oddity that looks like an integer overflow, but it shouldn't be. Excerpt from my program: #DEBUG echo "\n$Query\n"; #DEBUG $hResult = _do_query(__LINE__, $Query); # _do_query() simply executes mysql_query, and does nice error formatting if necessary $First = true; while ($Row = @mysql_fetch_array($hResult)) { if ($First) { $First = false; show_table_open($Myself); } echo '', '', $Row['source_code'], '', '', $Row['chromo_code'], '', '', $Row['type'], '', '', number_format($Row['min_exon_length']), '', '', number_format($Row['max_exon_length']), '', # '', $Row['min_exon_length'], '', # '', $Row['max_exon_length'], '', "\n"; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Automatic user login under NT
At 01:39 PM 6/12/02 , Barajas, Arturo wrote: > > From: Lazor, Ed [mailto:[EMAIL PROTECTED]] > >Hi, Ed. > > > and I'm pretty sure I'm not the only one he's helped. That > > garners even more respect - IMHO. > >I'm new on the list, so I really don't know Rasmus, or what he does. As >far as I've read messages, he seems to be really appreciated and >respected, one way or another. You can check out this bit from the PHP archives, written by Rasmus: http://www.php.net/manual/phpfi2.php#history and take a look through the credits http://www.php.net/credits.php and count how many times his name appears. In short, PHP sprang from his brain. Now, it springs from many brains. -steve +--------+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] Usiing FOREACH to loop through Array
At 3:27 PM -0700 6/29/02, Brad Melendy wrote: >Hi All, >I've stumped myself here. In a nutshell, I have a function that returns my >array based on a SQL query and here's the code: > >-begin code--- >function getCourses($UID) > { > global $link; > $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U, >tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = >$UID", $link ); > if ( ! $result ) > die ( "getRow fatal error: ".mysql_error() ); > return mysql_fetch_array( $result ); > } >end code > >I call this from a PHP page with the following code: > >begin code-- >$myCourses = getCourses($session[id]); >foreach ($myCourses as $value) > { > print "$value"; > } >end code--- > >Now, when I test the SQL from my function directly on the database, it >returns just want I want it to return but it isn't working that way on my >PHP page. For results where there is a single entry, I am getting the same >entry TWICE and for records with more than a single entry I am getting ONLY >the FIRST entry TWICE. > >Now I know my SQL code is correct (I am testing it against a MySQL database >using MySQL-Front) so I suspect I'm doing something stupid in my foreach >loop. I think your problem lies in a misunderstanding of the mysql_fetch_array() function. It doesn't return the entire result set in an array - just one record at a time. You can fix this in one of two ways: (1) Loop though the entire result set in your function: function getCourses($UID) { global $link; $ResultSet = array(); $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID", $link ); if ( ! $result ) die ( "getRow fatal error: ".mysql_error() ); while ($Row = mysql_fetch_array( $result )) { $ResultSet[] = $Row['C.CourseName']; } return $ResultSet; } ... $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print "$value"; } or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID", $link ); if ( ! $result ) die ( "getRow fatal error: ".mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print "", $Row['C.CourseName']; } (standard caveats about off-top-of-head, untested code apply) The reason you are getting the first record TWICE is becaouse of the default behaviour of the mysql_fetch_array() function. It returns both an associative array - ie, elements of the form => - and a numerically indexed array (0, 1, 2, etc.). You can alter this behaviour by the second parameter of the function: see http://www.php.net/manual/en/function.mysql-fetch-array.php -steve >I'm hoping someone will spot my dumb mistake. Thanks very much for any help >at all on this. > >Brad > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Usiing FOREACH to loop through Array
Oops! It's hot, it's Saturday, brain not functioning at 100%, made cut'n'paste error: or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID", $link ); if ( ! $result ) die ( "getRow fatal error: ".mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print "", $Row['C.CourseName']; } This last block of code should be while ($Row = getCourses($session[id])) { print "", $Row['C.CourseName']; } -steve -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Usiing FOREACH to loop through Array
At 7:35 PM -0700 6/29/02, Brad Melendy wrote: >Steve, >Thanks very much. You're welcome! >This make total sense to me. Now, I was pretty sure that >I was getting an array back from mysql_fetch_array because when I do a >'print $myCourses' without specifying any value, I just get 'array' which I >believe I am supposed to, IF it is truly an array. Anyway, I'm going to >revisit the mysql_fetch_array function right now. Thanks for your help, it >is greatly appreciated. > >...Brad Just to clarify a bit - mysql_fetch_array() DOES return an array - thus the name - but it is an array containing one record from the result set. For instance, if the result of the statement SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = 1 through the MySQL commandline was +-+ | C.CourseName| +-+ | Basketweaving | | Noodle twirling | | Poodle furling | | Puddle curling | +-+ then the first use of mysql_fetch_array($result) through PHP would retrieve the array 'C.CourseName' => 'Basketweaving', 0 => 'Basketweaving' the second call would retrieve 'C.CourseName' => ' Noodle twirling', 0 => ' Noodle twirling' and so on. If you had two columns in the result set: +-++ | C.CourseName| C.CourseNo | +-++ | Basketweaving | 12 | | Noodle twirling | 23 | | Poodle furling | 24 | | Puddle curling | 25 | +-++ you would get results like 'C.CourseName' => 'Basketweaving', 0 => 'Basketweaving', 'C.CourseNo' => 12, 1 => 12 and so on. The reason you get the doubled keys (associative & numeric) is for historical compatibility; to turn off the feature, and retrieve only the associated indexes (the behavior you normally want), you can use mysql_fetch_array($result, MYSQL_ASSOC); Incidentally, I just learned something here myself; there's a relatively new (>= version 4.0.3) function mysql_fetch_assoc() which does what you want...return ONLY the associated indexes. See: http://www.php.net/manual/en/function.mysql-fetch-assoc.php -steve >"Steve Edberg" <[EMAIL PROTECTED]> wrote in message >news:p05100300b943f2a7feef@[168.150.239.37]... >> At 3:27 PM -0700 6/29/02, Brad Melendy wrote: >> >Hi All, >> >I've stumped myself here. In a nutshell, I have a function that returns >my >> >array based on a SQL query and here's the code: >> > >> >-begin code--- >> >function getCourses($UID) >> > { >> > global $link; > > > $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers >U, >> >tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = > > >$UID", $link ); >> > if ( ! $result ) >> > die ( "getRow fatal error: ".mysql_error() ); >> > return mysql_fetch_array( $result ); >> > } >> >end code >> > >> >I call this from a PHP page with the following code: >> > >> >begin code-- >> >$myCourses = getCourses($session[id]); >> >foreach ($myCourses as $value) >> > { >> > print "$value"; >> > } >> >end code--- >> > >> >Now, when I test the SQL from my function directly on the database, it >> >returns just want I want it to return but it isn't working that way on my >> >PHP page. For results where there is a single entry, I am getting the >same >> >entry TWICE and for records with more than a single entry I am getting >ONLY >> >the FIRST entry TWICE. >> > >> >Now I know my SQL code is correct (I am testing it against a MySQL >database >> >using MySQL-Front) so I suspect I'm doing something stupid in my foreach >> >loop. >> >> >> I think your problem lies in a misunderstanding of the >> mysql_fetch_array() function. It doesn't return the entire result set > > in an array - just one record at a time. You can fix this in one of >> two ways: >> >> (1) Loop though the entire result set in your function: >> >> function getCourses($UID) >> { >>global $link; >> >>$ResultSet = array(); &g
Re: [PHP] Two cases going to same case?
At 5:18 AM -0400 6/30/02, Leif K-Brooks wrote: >I have a switch in a script I'm working on. I need to have case 1 >and 2 both to to case 3, but without case 1 going through case 2. >Is this possible? No, but you can do it this way: switch ($foo) { case 1: ... do_something(); break; case 2: ... do_something(); break; case 3: do_something(); break; } function do_something() { # this is the stuff that you want to do that is common to your # cases 1, 2 and 3 } This accomplishes the same thing. -steve -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Odd Request: Image 2 HEX
$hFile = fopen($PathToFile,'r'); $File = fread($hFile, $SizeOfLargestImageYouHave); fclose($hFile); $HexVal = bin2hex($File); This doesn't do any error checking or stripping of image headers that may be necessary; you'll have to use string functions (eg; substr() or maybe regexps) to do that. For more info, see: http://www.php.net/manual/en/function.fopen.php http://www.php.net/manual/en/function.fread.php http://www.php.net/manual/en/function.bin2hex.php -steve At 9:08 AM -0700 7/9/02, JSheble wrote: >I'm using a Zebra label printer in an application I have and in >order to display an image on the label, according to the ZPL II >printer language, any image must be converted to HEX code. Does >anyone hvae a code snippet or know of a free utility that will take >a graphic image (BMP, GIF, JPG, etc...) and convert it to HEX values? > >Thanx... > -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GD Lib
Are you compiling php with the --with-gd=shared option? Personally (Solaris 8, gcc 2.95.3 , php 4.1.1 and later) I've never been able to get the gd shared object to work (gd.so load errors), so I've always ended up compiling it into PHP. -steve At 1:23 PM -0400 7/9/02, Yang wrote: >Hi Dave: > >I have gd installed and now the configure, make and make install are working >fine. but aftere installation, I can't find any extension there. > >Yang > >"Dave Macrae" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >> > Hi there; >> > >> > I installed Apache2.0.39 and PHP4.2.1 on RedHat Linux 7.2. The >> > installation >> > procedure is fine. The php installation inlcude gd and some >> > extension, but I >> > can't find the php-gd.so on my computer. >> > >> > Anybody can help? >> >> Looks like the problem is that you haven't installed GD. >> > > Dave > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Check for Associative Array
At 12:57 PM -0400 7/18/02, Henning Sittler wrote: >What's the best way to check for an Associative Array? There is no >is_assoc() or similiar function listed in the manual (I don't think anyway). No, because AFAIK all PHP arrays are associative; there is no distinction between arrays & hashes as in Perl. >I'm using mysql_fetch_array() and I want to foreach only the assoc. part of >the array without using mysql_fetch_assoc(): > >foreach ($arr as $key=>$value) { > echo "$key:$value"; >} If you really don't want to use mysql_fetch_assoc(), you can use the second parameter of mysql_fetch_array(): $arr = mysql_fetch_array($ResultHandle, MYSQL_FETCH_ASSOC); This functions exactly like mysql_fetch_assoc(), and is available in PHP >= 3.0.7. See http://www.php.net/manual/en/function.mysql-fetch-array.php for more info. >But of course it show both the indexed array and the assoc array contents. >Is there an existing function to check this, or should I do one of these >things inside the foreach loop: > >A) set $last=value and just check if $value = $lastval > >B) check if the $key is just a number or just a string > >C) $key += 1 Lastly, you _could_ just step through the array using each() in a loop, and use only every OTHER array entry...but this is really funky and you shouldn't do it this way anymore. -steve > >?? Thanks, > > >Henning Sittler >www.inscriber.com > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Character Generator
Well, here's an untested script off the top of my head: function random_string($Ncharacters) { static $CharList = '0123456789abcdefghijklmnopqrstuvwxyz'; $String = ''; $Max = strlen($CharList)-1; for ($i=0; $<$Ncharacters; $i++) { $String .= $CharList{rand(0, $Max)}; } return $String; } For php < 4.2.0, you'll need to seed the random number generator first; see http://www.php.net/rand You could probably also make something up using rand in conjunction with ord(): http://www.php.net/ord Also see: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing -steve At 04:32 PM 11/10/03, Jason Williard wrote: I would like to have a script that randomly generates alpha-numeric characters. Does anyone know of any scripts that can do this or perhaps the basic code to generate random characters? Thank You, Jason Williard +----+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Display syslog file?
I don't know if the same syntax is available on Linux, but on Solaris I can use the 'tail -f' command to watch lines being appended to a file from the commandline.. You might be able to do something via passthru("tail -f $PathToSyslog"); in a frame on your page...although there might be socket_blocking or page flush() issues to experiment with - steve At 8:28 AM -0600 1/9/04, Carlton L. Whitmore wrote: I didn't make my last request very clear. I used lastlog as an example, but what I really want to do is open a syslog file (text file), that is coming in from a VPN box. I'd like to have it displayed live so I can scan it during the day. What is the best way to do this? Someone had suggested using cron, but I'm very new to Linux and PHP so I would need some help with that. Any help is appreciated, Carlton. -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | [EMAIL PROTECTED]: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can you recommend a good PHP includes tutorial?
And, you can even do this automatically using the auto_prepend_file and auto_append_file settings: http://us3.php.net/manual/en/configuration.directives.php These can be set in your Apache config file, php.ini or .htaccess, so you can control what files are used down to the lowest subdirectory level. Of course, if you need to include() in the middle of a page, or conditionally include files, these won't work - steve At 5:16 AM -0800 1/14/04, Freedomware wrote: Wow, that is a lot simpler than I imagined. Thanks for the tip! Jay Blanchard wrote: [snip] I thought this would be the easiest thing to learn, but I'm striking out right and left. I bought a book about PHP, but the includes examples don't work for me at all. I searched several forums and www.php.net, but it's hard to even zero in on a good tutorial. [/snip] http://www.php.net/include There is no tutorial for this because it is painfully simple to use. Create toBeIncluded.php -- Today is You're all done! Now create myIncluded.php -- Welcome! inlclude("toBeIncluded.php"); ?> All done! Now just place these files in the same directory in your web server and load myIncluded.php from the browser. You may have to pay close attention to the paths of the files, but it is pretty simple really. HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | [EMAIL PROTECTED]: 1001 Work units on 23 oct 2002 | | 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens... | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case ?
At 11:17 PM -0500 1/10/01, Jon Rosenberg wrote: >I know this is kinda silly. but, if I have the following, will the file >only be included when the case is matched or does require always bring in >the file regarless? > >case blah: >require('include.php'); >do something >break; > 'require' ALWAYS includes the file; 'include' is what you want here. The tradeoff is that include is slightly slower. For more info, see http://www.php.net/manual/function.include.php and http://www.php.net/manual/function.require.php -steve +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] case ?
At 2:29 PM +0900 1/11/01, Maxim Maletsky wrote: >here we go, from Zeev: > > > >As of PHP 4.0.3, the implementation of require() no longer behaves that > > >way, and processes the file 'just in time'. That means that in the 1st > > >example, the file will be processed a hundred times, and in the 2nd > > >example, it won't be processed at all. That's the way include() behaves > > >(in all versions of PHP) as well. > >November 14-th ... > > >Cheers, >Maxim Maletsky Aah; so I leaned something new today :) My production systems are still PHP3; PHP4.0.4 is still on my test system. - steve >-Original Message- >From: Maxim Maletsky >Sent: Thursday, January 11, 2001 2:26 PM >To: 'Steve Edberg'; Jon Rosenberg; PHP List . >Subject: RE: [PHP] case ? > > > > >'require' ALWAYS includes the file; 'include' is what you want here. > >not since v4.0.2(?) came out ... >I heard from Zeev that require() and include() behave now just about the >same. >Read our posting regarding this topic of 1-2 month ago.. > >Cheers, >Maxim Maletsky > > >The tradeoff is that include is slightly slower. For more info, see > > > http://www.php.net/manual/function.include.php > >and > > http://www.php.net/manual/function.require.php > >-steve +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] how to track haeder trouble???
At 6:34 PM +0100 1/11/01, Sebastian Stadtlich wrote: >Hi All > >my isp mumbels something about trouble with header changes with php since >it's >running in CGI mode. I diffuse remember a way to connect to a webserver with >telnet on port >80 and then typing something to request a page.. could somone please tell me >what that something >was? or a page that point's out stuff like that? > >thanks >Sebastian Offhand, I can't see what header changes might be causing trouble, but - To actually take a look at the headers returned, you can telnet to your web server, port 80 and then type an HTTP command. For instance: HEAD / HTTP/1.0 This will give you a summary of info, with headers, of your default index page. GET /some/path/page.php HTTP/1.0 , for example, will retrieve the entire page /some/path/page.php, including the HTTP headers. For more info on HTTP 1.1 (which most web servers should support by now), you can check out ftp://ftp.isi.edu/in-notes/rfc2616.txt (it's a ~412KB text doc). For a list of references to all HTTP protocols, extensions, proposals, etc. see http://www.w3.org/Protocols/ -steve +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Performance question
At 2:22 PM -0500 1/11/01, Ignacio Vazquez-Abrams wrote: >On Thu, 11 Jan 2001, John Guynn wrote: > > > Do I pay a performance penality for calling a file that only contains html > > code .php or .php3? In otherwords what is the php parser overhead if there > > is no php code in the file? > > > > John Guynn > > > > This email brought to you by RFCs 821 and 1225. > > > >Yes, because that file will be put through the parser regardless of whether or >not there's any PHP in it. The extent of this overhead depends on whether you're running PHP as a module or as a CGI. With CGI, the overhead is quite large, probably too much unless you have a really meaty server or a lightly-hit web site. For an Apache module, I recall a test someone ran > 1 year ago that resulted in an extra ~4 % load for parsing plain html pages through php (as opposed to just statically serving the html pages). This person had set his server to php-parse the .html extension. - steve >-- >Ignacio Vazquez-Abrams <[EMAIL PROTECTED]> > +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] regex
At 02:54 PM 1/12/01 , Jerry Lake wrote: >is it possible with regex to >change one or more text characters >followed by a space into the same >characters followed by a tab? > >Jerry Lake For example - $NewString = ereg_replace("([[:alpha:]]+) ", "\\1".chr(9), $String); This will convert a sequence of one or more alphabetic characters followed by one space to the same set of characters followed by a tab (that's the chr(9) part). If you want to match only a specific set of text characters - say, a, e, i, o and u - then you can use $NewString = eregi_replace("([aeiou]+) ", "\\1".chr(9), $String); Notice i used eregi_replace() instead of ereg_replace(); the 'i' means case INsensitive. Of course, there are other ways of doing this with preg_replace and str_replace, both of which are faster than ereg_replace (str_replace is the fastest); I happen to use ereg becaouse I'm most familiar with it, since it came along before the preg_ functions. As always, you can check out the docs: http://www.php.net/ereg_replace http://www.php.net/eregi_replace http://www.php.net/str_replace http://www.php.net/preg_replace -steve (The usual off-the-top-of-my-head-untested-code-snippet caveats apply) +--------+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] (530)754-9127 | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] changing strings to float vars
At 4:28 PM -0500 1/15/01, bill wrote: >Sometimes clients put a dollar sign "$" in a form that only needs a >number (like "1.50"). > >Is there a way to take a post variable and automatically convert it to a >float value, stripping off any non-numeric characters? > >I tried doubleval() without success and I can't use intval() because it >has decimals. > >kind regards, > $SanitizedNumber = ereg_replace('[^0-9.]', '', $NumberString); If you really need to make this a float variable, then you can add $Number = (float)$SanitizedNumber; although in most cases PHP handles type conversion correctly on-the-fly. - steve +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable method
At 4:53 PM -0800 1/18/01, Blaine Grady wrote: >Suppose I have: > $method = "doIt"; >inside a class. How do I construct the statment, using $method, to >call: > $this->doIt(); >I tried every combination I can think of but I keep getting "Call to >unsupported or undefined function" when doIt() is a proper method. I >have no problem with standard functions. >Thanks for any help. > Did you think of class foo { function bar() { $method = 'doIt'; $this->$method('yes'); } function doIt($Answer) { echo "Noodles are happy? $Answer"; } } It's been awhile, but I believe that should work. If not, give us more info: What version of PHP? What, exactly, DID you try? - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: RV: [PHP] Does PHP works with Netscape Web Server orIPlanet???
At 1:36 PM +0100 1/22/01, Aguilar Peña, Javier wrote: >It's me again. I've tried with IIS and PWS and everithing ok...but not >with Netscaspe which is the one I need. I assume you're talking about Netscape on Windows? If so, yes it runs fine, but only as a CGI - I used to have that setup until I moved to an Apache/PHP module configuration. Off the top of my head, I had (1) set up Windows file associations to associate .php extension with PHP.exe (2) created Shell CGI directories for all my php scripts There was a better way that someone had come up with that avoided step (1) by editing the mimetypes.conf (?) file and associating the php extension with the php executable within Netscape, but I can't remember that method offhand - it's been a while. Also, if you're looking for Netscape on Unix information, there used to be a website that explained how to compile PHP to run as a NSAPI module; unfortunately, that URL disappeared. I could dig up that info for you anyway, if you're interested. Lastly, I believe that PHP4 comes with experimental NSAPI support; check www.php.net or www.php4win.de - steve >Thanks again. > >> -Mensaje original- >> De: Aguilar Peña, Javier >> Enviado el: lunes 22 de enero de 2001 13:31 >> Para: '[EMAIL PROTECTED]' >> Asunto: [PHP] Does PHP works with Netscape Web Server or IPlanet??? >> >> Does PHP works with Netscape Web Server or IPlanet??? >> If it does.HOW >> >> [EMAIL PROTECTED] >> Thanks -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Getting warning using split
At 7:33 AM -0500 1/23/01, Brian Clark wrote: >Hello Matt, > >(MW == "Matt Williams") [EMAIL PROTECTED] writes: > >MW> $query_string = split("+",$search); > >$query_string = explode('+', $search); > >-Brian > Just to explain the error - split() takes a regular expression for its first argument; '+' is a special character for regular expressions, and is not valid by itself. That's why you're getting an error. For more info on regular expressions, there have been links to good tutorials that pop up from time to time on this list; also, I think there are a few references mentioned in the online docs for the ereg_ and preg_ functions. You can also get the O'Reilly book 'Mastering regular expressions.' That being said, though, explode() is probably a better function to use here. If you don't need the functionality of regexps, explode() is faster. -steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] non-php related question.
Try wget http://sunsite.dk/wget/index.html At 12:05 PM -0500 1/23/01, Jason Jacobs wrote: >Hey guys and gals! I have my personal site on go.com, and I wanna move it. >The problem is I don't have it all backed up on my machine (I think I only >have some of the images), but I want to move it to my server at work. Does >anyone know of a script of some sort that will go to my site, copy all the >files to a specified folder, and follow my internal links? Thanks for the >info. > -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Help w/ quotes/html and data from MySQL
At 4:47 PM -0500 1/23/01, Shane McBride wrote: >I have a field in MySQL that holds data that may look like this: > >Rose Painting"Looks really nice, blah, blah"25.00 > >Now, I want to pull that data back into a form to edit. >Here's how I have unsuccessfully been doing it: > >?> > beginning code >Description: >rows=\"5\"> >...ending code >?> > >I looks like that the embedded html in the MySQL data is actually >being "rendered" (for the lack of a better term). >How can I get the whole chunk of data back into the form? > Well, if you're using PHP: echo 'Description:', '', htmlentities($description), '' ; Presumably, other web development languages have an equivalent construct to PHP's htmlentities(). Also, the value of a textarea tag is not put in a 'value' attribute within the tag as with the INPUT tag; it is put in the textarea 'container' - that is, between the and tags. - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Form data is not "remembered"
At 2:41 AM -0800 1/24/01, Klepto wrote: >Try the "GET" method in the form. > >Jaks >- Original Message - >From: Alain Fontaine <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Wednesday, January 24, 2001 2:11 AM >Subject: [PHP] Form data is not "remembered" > > >> Hi, >> >> I have a page with a couple of form fields that are being POSTed to a >> processing PHP script. The page that contains these form fields is itself >a >> PHP page that uses sessions and so on. >> >> I have to make "server-side data validation" on the fields because of >their >> complexity. When the user hits submit and comes to the result page, if >there >> was any error I ask the user to go back to the form and correct the >> mistakes, using either his browser BACK button or by clicking on a link >that >> does a javascript:history.back(). >> >> The problem is, when the user gets back to the form page, all of the >values >> he had typed in are gone, and he has to start all over again. Does anyone >> have an idea why this is so, and how to circumvent it without saving the >> user data into a session variable and then setting it back again once the >> user hits the form page again ? I have seen many pages where your previous >> data would stay in the form after you make a "Back" operation, but here, >it > > disappears. > > Some browsers will save the entered info when you hit the BACK button, some won't; it also depends on your HTTP header settings (no-cache, must-revalidate, etc.). Probably bad idea to rely on that. In a nutshell, if your validation fails, don't tell the user to hit the back button. Instead, redisplay the form with the data fields already filled in. I usually write my form display & process programs something like this (assuming $Submit is the name attribute of the submit button): ... if ($Submit = 'Enter your data') { $ErrorList = validate_form_data(); if (is_array($ErrorList)) { show_form($ErrorList); } else { process_data(); } } else { show_form(); } ... Where: validate_form_data is a function that returns an array of error messages like $ErrorList[] = , or FALSE if all tests passed. If there are errors, I redisplay the form with entered data (from $HTTP_POST_VARS or wherever), and error messages displayed alongside the appropriate form fields. show_form displays the entry form, with any existing data (from HTTP_POST_VARS, etc.) filled in and error messages, if any, displayed. Basically, the FORM tag action attribute refers to the same program as displayed the form - that is, $PHP_SELF. Hope this is clear...I getting tired, and I don't even think an intravenous drip of concentrated Mountain Dew syrup will help. - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Editors, again (was Re: [PHP] Beginner in php!)
At 4:40 PM +0600 1/24/01, Tshering Norbu wrote: >Here is collection I got from this list; > >www.editplus.com >www.codecharge.com >www.phpedit.com >www.ultraedit.com > See this list: http://www.itworks.demon.co.uk/phpeditors.htm Some of the comments are a bit out of date - for instance, BBEdit 6.0 (Macintosh) now has PHP syntax highlighting - but it's a got starting point. - steve > >- Original Message - >From: kaab kaoutar <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Wednesday, January 24, 2001 4:28 PM >Subject: [PHP] Beginner in php! > > >> Hi guys! >> >> I'm working on an NT workstation, i used to work with asp, but i heard a >lot >> about php! that i decided to start working with it ! >> so i'm using PWS4 and i'm wondering which free php editor is more suitible >> for me ? and also what links to get free more tutorials, i got one of >phpnet >> but still >> >> Regards >> _ > > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. >> -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: AW: [PHP] eval() to string???
>-Ursprüngliche Nachricht- >Von: Robert S. White [mailto:[EMAIL PROTECTED]] >Gesendet: Mittwoch, 24. Januar 2001 16:20 >An: [EMAIL PROTECTED] >Betreff: Re: [PHP] eval() to string??? > > >How is this going to help me? > >I want to evaluate the code in $php_code to *another* string... > From http://www.php.net/manual/en/function.eval.php : "A return statement will terminate the evaluation of the string immediatley. In PHP 4 you may use return to return a value that will become the result of the eval() function while in PHP 3 eval() was of type void and did never return anything." So, if you're using PHP4, just ensure that there is a return in$php_code that returns the desired value: $thing = eval($php_code); It's helpful to read the notes at the above URL - escaping things correctly for eval() can be tricky... - steve >- Original Message - >From: Thomas Weber <> >To: Php-General <> >Sent: Wednesday, January 24, 2001 10:14 AM >Subject: AW: [PHP] eval() to string??? > > >> try >> >> eval("\$php_code;"); >> >> -Ursprüngliche Nachricht- >> Von: [ rswfire ] [mailto:[EMAIL PROTECTED]] >> Gesendet: Mittwoch, 24. Januar 2001 15:36 >> An: [EMAIL PROTECTED] >> Betreff: [PHP] eval() to string??? >> >> >> I want to evaluate some PHP code to a string. How can I do this? >> >> $php_code = "echo 'hello';" >> >> I would like to evaluate the code to "hello" in another string... >> >> > > -- -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Loop Through all Querystring Variables
At 3:07 PM -0700 1/24/01, Karl J. Stubsjoen wrote: >What is the simplest way to set up a procedure to loop through all passed >querystring values and/or form values? > >I'm very new to PHP, and don't know how to set up loops at all. > reset($HTTP_GET_VARS); while (list($VariableName, $VariableValue) = each($HTTP_GET_VARS)) { echo "GET variable $VariableName was set to $VariableValue\n"; } Of course, you would want to do your own processing in place of the echo. If you want to use POSTed or cookie variables, replace the _GET_ in the above snippet with _POST_ or _COOKIE_, respectively. The reset(), by the way, resets the array pointer to the beginning of the array. It's not always needed, but I tend to do it anyway. It IS necessary, however, ig you use the above snippet within an enclosing loop. - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple function returns
At 9:08 PM -0800 1/24/01, jeremy brand wrote: >$array[0] will be the lang_pref and $array[1] will be the >currency_pref. > >Jeremy An easy way to read the returned array values into scalar variables is: list($lang_pref, $currency_pref) = PrefChange($language, $currency, $state); You can only do this if your PrefChange function _always_ returns the same number of elements (two here; it could be any number). If you have a function that - for example - returns a 2-element array or FALSE if there's an error, then you have to do something a little more complex: $Stuff = PrefChange($language, $currency, $state); if (is_array($Stuff)) { # ...do stuff with $Stuff ! } else { # ...show error message } - steve >Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: [EMAIL PROTECTED] >http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more >- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > "LINUX is obsolete" -- Andy Tanenbaum, January 29th, 1992 >- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >http://www.JEEP-FOR-SALE.com/ -- I need a buyer > Get your own Free, Private email at http://www.smackdown.com/ > >On Thu, 25 Jan 2001, Jamie wrote: > >> Date: Thu, 25 Jan 2001 13:04:27 +0800 >> From: Jamie <[EMAIL PROTECTED]> >> To: PHP <[EMAIL PROTECTED]> >> Subject: [PHP] multiple function returns >> >> Can anyone help me I'm trying to read two results from a function by passing >> them out via an array but I'm not sure how to access them once I have done >> that. In the PHP manual it shows a list call which I can't seem to even find >> what the hell it does the code below runs without any errors but does not >> seem to work. >> >> here the function gest passed the language and currency preference and a >> variable (1,0) to decide what it will do with them - update the preferences >> of the user or read out and define the preferences. (once updated I want it >> to read out the prefs aswell) >> >> function PrefChange($lang,$curry,$state){ >> global $DB_Server, $HTTP_Host, $DB_Login, $DB_Password, $DB_Name, $DocRoot ; >> >> if ($state){//read preferences from page >>if (!($result = mysql_db_query($DB_Name,"SELECT language_pref, >> currency_pref FROM users WHERE user_id ='$cookie_user'"))){ >> DisplayErrMessage(sprintf("internal error %s %s %s %d:%s\n",$DB_Server, >> $DB_Login, $DB_Password, >> mysql_errno(), mysql_error())); >> while ($row = mysql_fetch_array($results)){ >> $lang_pref = $row["language_pref"]; >> $currancy_pref = $row["currency_pref"]; >> return array($lang_pref,$currancy_pref); >> } >> } >> } else {///update preferences from page >>if (!($result = mysql_db_query($DB_Name,"UPDATE users SET >> language_pref='$lang' AND currency_pref='$curry' WHERE >> user_id='$cookie_user'"))){ >> DisplayErrMessage(sprintf("internal error %s %s %s %d:%s\n",$DB_Server, >> $DB_Login, $DB_Password, >> mysql_errno(), mysql_error())); >> PrefChange(0,0,1) ; >> } >> } >> } >> >> >> an example of what I'd like to do when calling the function (here I'm only >> reading the prefrences from the DB ), a select box that is showing the >> preference that is chosen with the preference read from the above function >> and the list created by the function below >> >> >> > list ($form_language_pref, $form_currency_pref) = PrefChange(0,0,1); >> >>$select_id = $form_language_pref; >>$db = mysql_connect("$DB_Server", "$DB_Login, $DB_Password"); >>mysql_select_db("$DB_Name",$db); >> $results = mysql_query("SELECT * FROM language ORDER BY language >> ",$db); >> >>while ($row = mysql_fetch_array($results)){ >>$rowid = $row["language_id"]; >>$name = $row["language"]; >>if ($rowid == $select_id) { > > echo("$name\n"); >>} else { >>echo("$name\n"); >>} >> // endwhile; >>} >> echo(""); >> ?> > > > -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] finding the difference
At 3:16 AM -0500 1/25/01, [EMAIL PROTECTED] wrote: >I have a date and time stored in the following format: > >day:month:year:hour:minutes > >Example 27:01:2001:08:13 > >I want to work out the difference between that and the current time on my >server, but I can`t find any math functions in the PHP manual that allows you >to work out the diference. In the end I hope to be able to display '2 days 23 >hours and 55 minutes' type results, similar to the way in which eLance.com >shows the time remaining on a project. Anyone have any suggestion if it is at >all possible? > >Thanks >Ade > Take a look under date/time functions: http://www.php.net/manual/en/ref.datetime.php You want to convert your stored time into a Unix timestamp (that is, seconds since midnight 1 jan 1970), subtract the unix timestamp of the current time, and then display the result in your desired format: $Deadline = ' 27:01:2001:08:13'; $Bits = explode(':', $Deadline); $TimeDiff = mktime($Bits[3],$Bits[4],$Bits[5],$Bits[1],$Bits[0],$Bits[2]) - time(); # $TimeDiff is now the time difference, expressed in seconds. # Now, use modulo operator repeatedly to get day, hour & minute values. # BTW, there are 86400 seconds/day, 3600 seconds/hour. $NDays = $TimeDiff % 86400; $R = $TimeDiff - ($NDays * 86400); $NHours = $R % 3600; $R = $R - ($NHours * 3600); $NMinutes = round($R/60); echo "You have $NDays days, $NHours hours and $NMinutes left!"; If you're feeling obfuscatory, you could compact the calculations into (I think): $NHours = ($R = $TimeDiff - (($NDays = $TimeDiff % 86400) * 86400)) % 3600; $NMinutes = round(($R - ($NHours * 3600))/60); Why you would _want_ to do this, I don't know. I suppose if you're an ex-FORTRAN programmer frustrated by the lack of assigned and computed GOTOs and want to take it out on others, maybe. OK, now I'm rambling. And showing my age... - steve Usual untested, off-top-of-head, no-warranty code caveats apply. -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] How do I see the data in list()?
At 11:33 AM -0500 1/25/01, Scott Fletcher wrote: >Hi! > > When I use the echo to see what is inside the list(). Instead I got the >message on screen saying "ArrayArray". > > The array are being assigned first then then list come second. ie. > > $test = array(); > $test1 = array() > > list($test,$test1); > >--- > When I do "echo list($test,$test1);", it doesn't work. > > What are the better way to see the data in the array? > Are these actual program snippets? If they are then (1) '$test1 = array()' line is missing a trailing ';' (2) The statement 'list($test,$test1);', to the best of my knowledge, does nothing in this context. (3) From your echo statement, you should see the output 'list(Array,Array)' - functions and language constructs aren't evaluated in double-quoted strings; only variables. It would make more sense to me to have something like $test = array('bean', 'noodle', 'wednesday'); $test1 = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); $foo = array($test, $test1); Then you could display these values like so: If you have PHP4, use print_r() or var_dump(): echo print_r($foo); See http://www.php.net/manual/en/function.print-r.php http://www.php.net/manual/en/function.var-dump.php I haven't used either of these functions, so I don't know exactly what the output looks like. It says var_dump() was available in PHP 3 after 3.0.5, but I'm not entirely sure that's true. If it is, it must have been undocumented for a while. An alternative display method would be something like (a little more cumbersome, but works in PHP3 & 4): for ($i=0; $i\n"; } } Also, instead of the $test = array('bean', 'noodle', 'wednesday'); $test1 = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); $foo = array($test, $test1); way of declaring the $foo array, you could also say $foo = array( array('bean', 'noodle', 'wednesday'), array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot') ) or $foo[0] = array('bean', 'noodle', 'wednesday'); $foo[1] = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); See http://www.php.net/manual/en/language.types.array.php for more information. - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] VAR and variables
At 3:00 PM -0600 1/25/01, Matt wrote: >I have a question that may seem kind of silly, but I'm curious... > >When using PHP why would one use "var" to define a variable as >opposed to just regularly creating it? Because that's the way it is ;). The var is part of the syntax of a class definition; it isn't used anywhere else. I don't know the actual deep reason for having it, as far as the parser is concerned, but it does make it clear - at least to me - what the class variables are. You can also initialize the variable here, too: var $a = 5; >For example, if I have a class defined as below: > >class Simple { > var $a; > > function Simple() { > $this->a = 5; > } > > function first() { > return $this->a; > } > >} > > >This class, when created, sets the variable $a to 5, and the >function first returns the value in $a my question is could I >omit the var and still have it function in this fashion? What is the >purpose of it? > >Also, can I access this variable through the same -> convention, >i.e. would the following be allowed? > >$test = new Simple(); >echo $test->a; > > Yep. You can also _set_ $a this way: $test = new simple; $test->a = 77; echo $test->first(); will display 77. See http://www.php.net/manual/en/language.oop.php for more info. - steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Using a variable to select what variable to use...???
At 9:32 AM -0800 1/26/01, Brandon Orther wrote: >Hello, > >I am doing a do loop and I want it to change what variable to use each >run... > >First time use: $run1 > >Second time use: $run2 > >Third time use: $run2 > >I hope you can understand what I am saying. > 'Variable variables'; see http://www.php.net/manual/en/language.variables.variable.php If you meant $run3 on the third time line, then you can use for ($i=1; $i<$SomeNumber; $i++) { $SomeValue = some_function(${run$i}); } Or, use could say for ($i=1; $i<$SomeNumber; $i++) { $VarName = "run$i"; $SomeValue = some_function($$VarName); } If you actually _wanted_ to use '$run2' on the third time, I'm interpreting that to mean you want to limit the maximum value of the digit to 2. If so, you could do for ($i=1; $i<$SomeNumber; $i++) { $VarName = 'run'.max($i, 2); $SomeValue = some_function($$VarName); } -Steve > >Brandon Orther >WebIntellects Design/Development Manager >[EMAIL PROTECTED] >800-994-6364 >www.webintellects.com >-------- -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] isset()
I would do this: if (!$AgeChild) $AgeChild = 'NA'; More compact, easier to read (to me, anyway). This presumes that a value of '' (empty string, interpreted by PHP as false) is NOT a valid value here. As far as your sniplet goes, it is possible that there may be some PHP type-casting issues here, depending on: whether $AgeChild is numeric or string; the fact that the STRING "false" isn't equivalent to the CONSTANT false, the use of == vs. ===. Time to check out the docs - specifically the types and variables sections (also the functions->variables section)... - steve At 5:07 PM -0600 2/22/01, Jacky@lilst wrote: >People >I tried to check if teh field has set a vaule in it before submit >using isset with the sniplet below > >if ((isset($AgeChild))=="false") { >$AgeChild = "NA"; >} > >The resule is that it always displays NA whether or not it has vaule >in the field, what is the correct way of using isset for this >purpose? Or should I use empty() ? >Jack >[EMAIL PROTECTED] >"There is nothing more rewarding than reaching the goal you set for yourself" -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Using while as for...
At 12:44 PM -0800 2/24/01, Felipe Lopes wrote: >I was trying to code the following script using while instead of for, >but I'm havig a lot of problems...Is it possible to do what I want? > >for ($count = 0; $count <= 10; $count++){ >echo "Number is $count \n"; >} > >Could anyone tell me how is it with while instead of for?? >Thank you!! $count = 0; while ($count <= 10) { echo "Number is $count \n"; $count++; } I think - if you're feeling obscure - that $count = 0; while (($count <= 10) && print 'Number is '.$count++." \n") {} will work too. As will - using alternate while syntax - $count = 0; while ($count <= 10): echo 'Number is '.$count++." \n"; endwhile; See: http://www.php.net/manual/en/control-structures.while.php for more info. -steve >Felipe Lopes >MailBR - O e-mail do Brasil -- http://www.mailbr.com.br >Faça já o seu. É gratuito!!! -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Newbie: why do I get this error?
At 3:47 PM +0530 2/26/01, Harshdeep S Jawanda wrote: >Hello everybody, > >I am a newbie, so please help me out with my rather basic question. > >Please take a look at the following code snippet: > > class HTMLTable extends HTMLElement { > var $attributes; > > function HTMLTable() { > $attributes[] = array("border", "0"); > $attributes[] = array("cellpadding", "0"); > // and some other things > } > > function emit() { > // I get an error on this line > $arrLength = count($this->attributes[1]); > } > } > >On the line indicated above, I get the error: "Warning: Undefined >property: attributes in html_base_classes.inc on line " > >Can anybody give me a clue as to why this is happening? In your HTMLTable() function, use $this->attributes[] = array("border", "0"); $this->attributes[] = array("cellpadding", "0"); otherwise, PHP thinks $attributes is a variable local to that function, rather that a class variable. -steve >-- >Regards, >Harshdeep Singh Jawanda. > -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] How to disable some functions?
At 4:54 PM + 2/28/01, Philip Reynolds wrote: >Batonik's [[EMAIL PROTECTED]] 15 lines of wisdom included: >:>Hi, >:> >:> I've heard that it is possible, for security reasons, to disable >:>such functions like phpinfo(). How can I do this? > >You can edit the sources... >PHP4: $PHP_BASE_DIR/ext/standard/basic_functions.c > >You're looking for a struct called >function_entry basic_functions[] > >On my version (4.0.4-pl1) it's on line 91. >Your functions are listed there.. > >for example, delete line "PHP_FE(time, NULL)" >which is on line 100 on my version disables the time function. >However, why you want to disable functions is beyond me, to make PHP >"safe" you're going to have to disable a LOT of functions.. > >There might be some PHP4 way to disable functions, I think there >might be some way to do it from php.ini, but I can't find it >offhand. >Phil. > It's not documented yet at http://www.php.net/manual/en/configuration.php , but you can use the following in your php.ini file: disable_functions = ; This directive allows you to disable certain ; functions for security reasons. It receives ; a comma separated list of function names. ; This directive is *NOT* affected by whether ; Safe Mode is turned on or off. I presume you could use the php_value disable_functions phpinfo syntax in your httpd.conf or .htaccess (you might need to use php_admin_value instead of php_value). This is available in php 4.0.4; I don't know about availability in earlier versions. I don't use this, though, so I'm just copying from the provided .ini file. -steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Need an array parser(CONT)
At 12:33 PM -0800 2/28/01, Dallas K. wrote: >I am looking for somthing that will parse a multidimentional array of any >size, and return a key / value listing for debugging > >Example: > >if I have an array such as... > >$arr[name] = dallas >$arr[address][city] = austin >$arr[address][state] = Texas >$arr[somthing][somthing_else][blah1]= some_value1 >$arr[somthing][somthing_else][blah2]= some_value2 >$arr[somthing][somthing_else][blah3]= some_value3 > >I would want the result to be displaied as: > >ARR > name --- dallas > address --- city --- austin > address --- state --- Texas > somthing --- somthing_else --- blah1 --- some_value1 > somthing --- somthing_else --- blah1 --- some_value1 var_dump($arr) or print_r($arr) --- see http://www.php.net/manual/en/function.var-dump.php http://www.php.net/manual/en/function.print-r.php -steve -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Stripping HTML selectively?
At 09:43 PM 3/3/01 , Erick Papadakis wrote: >Thanks Brian, I have tried the allowable tags, but I need to remove the >ATTRIBUTES of a tag, not the tag itself. STRIP_TAGS totally removes the tag, >and ALLOWABLE_TAGS lets the tag be. WHat I wish to do is let the main tag be >but remove its attributes, as follows: > > Original text: > Hi! > > Parsed text: > Hi! > >Thanks/erick Well, in this case, you'd have to use regular expressions. One way to do it would be: $SanitizedString = ereg_replace('<[[:space:]]*([[:alnum:]]+)[^>]*>', "<\\1>", $String); this _should_ work (haven't tested it). If you wanted to remove some tags entirely, and then remove the attributes of the remaining tags, you could (1) use strip_tags() with a list of allowable tags, then (2) run the regexp above. Incidentally, the above regexp also removes leading spaces from the tag. Eg, < font style="unreadable"> becomes . If you don't want, that user the regexp '<([[:space:]]*[[:alnum:]]+)[^>]*>' instead. - steve >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.230 / Virus Database: 111 - Release Date: 25-Jan-01 ++ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] (530)754-9127 | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] session in php3
At 3:28 PM -0600 3/7/01, Jacky wrote: >Hi people >I got problem of how to assign session value in php3. As far as I >know, all syntax in manual talks about php4 syntax only. How am I >going to do that? >best In PHP3, you'll have to create your own session functions, or use a library like PHPLIB (phplib.netuse.de). -steve >Jack >[EMAIL PROTECTED] >"There is nothing more rewarding than reaching the goal you set for yourself" -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ASP vs PHP
At 11:48 PM -0500 3/11/01, Rick St Jean wrote: >I was told by someone that it is possible with apache. You can have >something parse >the page once then be parsed by something else. I don't know how >and I have never seen >it but I have been told that it is possible. > >Rick That would be 'stacked request handlers'...not possible, AFAIK, with any of the 1.x versions, but supposedly Apache 2.0 can do it. Check out httpd.apache.org; v2.0 is still alpha. - steve > >At 11:28 PM 3/11/01 -0500, Michael Kimsal wrote: >>You're comparing a framework to a language. >> >>ASP is a technology which allows code for different languages to be >>embedded in a file >>parsed by a webserver (IIS). To accomplish this, different >>languages need to be written >>as modules for that webserver. MS has VBScript (default language), >>JScript and PerlScript >>(anyone know of any more?). If someone was to write PHP to be an >>ASP/IIS module >>that could be executed under the ASP framework, then yes. Until >>then, no. I also >>don't think it's a likely scenario, but I've been wrong many times >>before in my life. :) >> >> >> >>Chris Anderson wrote: >> >>> This is going to sound like heresy, but is there any way to use >>>ASP and PHP in the same fle/page? Seperated of course. >> >> >>-- >>PHP General Mailing List (http://www.php.net/) >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >>To contact the list administrators, e-mail: [EMAIL PROTECTED] > >## ># Rick St Jean, ># [EMAIL PROTECTED] ># President of Design Shark, ># http://www.designshark.com/ ># Quick Contact: http://www.designshark.com/messaging.ihtml ># Tel: 905-684-2952 >## > -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Extract from string
At 11:07 PM +0200 4/14/01, n e t b r a i n wrote: >Hi all, >anyone have or know where I can find a small function in order to extract >from a string the most relevant words in it? > >something like this: > >$var="I love coffe ... Coffe is from Brazil and coffe with milk .."; >$occurence=2; >//$occurence means word that are repeat 2 or more times >my_dream_funct($var,$occurence); >//the funct now return the word _ coffe _ > >many thanks in advance >max > >ps.plz note: I need that it works on php3 > Well, just offthetopofmyhead: function word_occurrence($word,$phrase) { $word = strtolower($word); # this way, $phrase = strtolower($phrase); # case is irrelevant $Bits = split($word.'[^[:alnum:]]*', $phrase); return (count($Bits)-1); } I tested this, and it works fine (php 3.0.12) EXCEPT it counts 'coffecoffe' as TWO words, not zero. If that's the behavior you want, then it's fine. Now I'm intrigued...I want to find a single regular expression that will NOT match 'coffecoffe'. Perhaps preg_ functions (available on PHP >= 3.0.9). And, I tried things like split('[^[:alnum:]]*'.$word.'[^[:alnum:]]*', " $phrase ") ...didn't work. -steve -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Extract from string, version 2.0
OK, this is less elegant (to me, anyway), and probably a bit slower, but: function word_occurrence($word,$phrase) { $word = strtolower($word); # this way, $phrase = strtolower($phrase); # case is irrelevant $Bits = split('[^[:alnum:]]+', $phrase); $count = 0; for ($i=0; $iHi all, >anyone have or know where I can find a small function in order to extract >from a string the most relevant words in it? > >something like this: > >$var="I love coffe ... Coffe is from Brazil and coffe with milk .."; >$occurence=2; >//$occurence means word that are repeat 2 or more times >my_dream_funct($var,$occurence); >//the funct now return the word _ coffe _ > >many thanks in advance >max > >ps.plz note: I need that it works on php3 > Well, just offthetopofmyhead: function word_occurrence($word,$phrase) { $word = strtolower($word); # this way, $phrase = strtolower($phrase); # case is irrelevant $Bits = split($word.'[^[:alnum:]]*', $phrase); return (count($Bits)-1); } I tested this, and it works fine (php 3.0.12) EXCEPT it counts 'coffecoffe' as TWO words, not zero. If that's the behavior you want, then it's fine. Now I'm intrigued...I want to find a single regular expression that will NOT match 'coffecoffe'. Perhaps preg_ functions (available on PHP >= 3.0.9). And, I tried things like split('[^[:alnum:]]*'.$word.'[^[:alnum:]]*', " $phrase ") ...didn't work. -steve -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Extract from string, version 3.0
Sheesh! No one should let me reply to email without sufficient caffiene! Now, I actually just read and grokked your question... I haven't tested this. And, I included a line that removes apostrophes (eg; "steve's" becomes "steve"). You can comment that line out if this doesn't suit your needs. The function returns an array of all words that meet or exceed your threshold count, sorted by decreasing frequency (you can remove the sort section too, if you don't need it). Sorry about the previous two messages... function your_dream_function($phrase, $threshold) { $phrase = strtolower(trim($phrase)); $WordList = $Temp = array(); $Bits = split('[[:space:]]+', $phrase); for ($i=0; $i= $threshold) { $WordList[] = $Temp[$i]; } } return ($WordList); } Some notes: (1) I can't recall if PHP3's arsort() would treat the array value as a string or as a numeric. I think it would always treat the value as a string (meaning that '2' would come before '12' in an descending sort), so in that case you would have to modify the function above in one place (only if you wanted the sort): Replace $Temp[$Bits[$i]]++; in the first for loop with $x = $Temp[$Bits[$i]]++; $Temp[$Bits[$i]] = substr(1+$x, 1); This should left-pad the number with zeros (for up to occurrences found), so that the ASCII sort sequence is in numeric order. Using PHP4's arsort($Temp, SORT_NUMERIC) would be much handier! (2) Iff (if and ONLY if) you are using the sort, you could get a slight speed improvement by modifying the second for loop as follows; replace if ($Temp[$i] >= $threshold) { $WordList[] = $Temp[$i]; } with if ($Temp[$i] >= $threshold) { $WordList[] = $Temp[$i]; } else { break; # all subsequent words will be below the threshold } Again, this is all untested code. -steve At 3:43 PM -0700 4/14/01, Steve Edberg wrote: >OK, this is less elegant (to me, anyway), and probably a bit slower, but: > >function word_occurrence($word,$phrase) { >$word = strtolower($word); # this way, >$phrase = strtolower($phrase); # case is irrelevant > >$Bits = split('[^[:alnum:]]+', $phrase); >$count = 0; >for ($i=0; $i if ($Bits[$i] == $word) { $count++; } >} > >return ($count); >} > >It should also handle hyphenated & apostrophied (is that a word?) >words correctly, such as > > coffe's a drag >or > coffe-heads are strange > >If you want to count words that INCLUDE dashes or apostrophes, you'd >have to use "[^[:alnum:]'-]+" in the split() function. Or, just >break the string up by whitespace, and use '[[:space:]]+'. > > -steve > > > >---Original Message --- >At 11:07 PM +0200 4/14/01, n e t b r a i n wrote: >>Hi all, >>anyone have or know where I can find a small function in order to extract >>from a string the most relevant words in it? >> >>something like this: >> >>$var="I love coffe ... Coffe is from Brazil and coffe with milk .."; >>$occurence=2; >>//$occurence means word that are repeat 2 or more times >>my_dream_funct($var,$occurence); >>//the funct now return the word _ coffe _ >> >>many thanks in advance >>max >> >>ps.plz note: I need that it works on php3 >> > > >Well, just offthetopofmyhead: > >function word_occurrence($word,$phrase) { >$word = strtolower($word); # this way, >$phrase = strtolower($phrase); # case is irrelevant > >$Bits = split($word.'[^[:alnum:]]*', $phrase); > >return (count($Bits)-1); >} > >I tested this, and it works fine (php 3.0.12) EXCEPT it counts >'coffecoffe' as TWO words, not zero. If that's the behavior you >want, then it's fine. Now I'm intrigued...I want to find a single >regular expression that will NOT match 'coffecoffe'. Perhaps preg_ >functions (available on PHP >= 3.0.9). > >And, I tried things like > > split('[^[:alnum:]]*'.$word.'[^[:alnum:]]*', " $phrase ") > >...didn't work. > >-steve > >-- >+--- 12 April 2001: Forty years of manned spaceflight ---+ >| Steve Edberg University of California, Davis | >| [EMAIL PROTECTED] Computer Consultant | >| http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | >+-- www.yurisnight.net --+ > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL
Re: [PHP] var question
You can also look at environment variable $QUERY_STRING. For example, if ($HTTP_SERVER_VARS['QUERY_STRING'] == 'login') { ...do log in procedure If register_globals is on, all you need is if ($QUERY_STRING == 'login') If you might be passing other parameters in the URL, and want to ignore case, you could use something like: if (eregi('login', $QUERY_STRING)) { This would match www.blah.com?login www.blah.com?LogIn www.blah.com?login&user=herman_hollerith but it would also match www.blah.com?sloginthemud www.blah.com?login0 So, a little regular expression twiddling might be in order. For more info, see: http://www.php.net/manual/en/language.variables.predefined.php http://www.php.net/manual/en/ref.regex.php http://www.php.net/manual/en/ref.pcre.php -steve At 02:43 PM 4/16/01 , Plutarck wrote: >Add an "=" on the end of your url. Viola. > > >-- >Plutarck >Should be working on something... >...but forgot what it was. > > >""Jeroen Geusebroek"" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > Hi Guys, > > > > I have a question about the way PHP handles var/strings. > > > > Let's say i have this URL: http://foo.bar.com/?login. > > And in my script i have this code: > > > > if($login) { echo "blab"; } or > > if(isset($login)) { echo "blab"; } > > > > It always returns FALSE. I think that is because the string > > is empty. Shouldn't PHP, even if a var is empty, put it in > > his var-list? > > > > Is there another way to do what i want? > > > > Thanks, > > > > Jeroen Geusebroek > > ++ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] (530)754-9127 | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] How do I detect if mysql_connect failes?
At 5:22 AM +0200 4/20/01, Marcus Rasmussen wrote: >I CAN detect if an erro occours. (just some error I did) > >I still don't get any return from mysql_errno() or mysql_error() >I don't iether get a return from mysql_errno() or mysql_error() when >I do not surpress with @ (the function, mysql_connect(), then prints >a message.) > >Guess I could surpress and write the error message myself, but I >just want the original one, wich I should be able to get with >mysql_error() > >PS. It is only mysql_connect that do it. I think this used to be in the docs or notes, but I couldn't find it when I did a quick search. As I understand it, mysql_error() and mysql_errno() only return errors on an active connection. So, if the error occurs on mysql_connect/pconnect(), they will not return anything. So, you can do something like: $LinkId = @mysql_connect(...); if (!$LinkId) { call error_function('Unable to connect to database;); exit; } or, more simply: $LinkId = @mysql_connect(...) or die('Unable to connect to database'); There's no way that I know of to get more details on WHY the connect failed other than not using the '@' and seeing what the mysql_connect error message does. In PHP4, you might be able to catch that message using the output buffering functions, then format that the way you want. See http://www.php.net/manual/en/ref.outcontrol.php for more info on output buffering. -steve >Marcus R. > >*** REPLY SEPARATOR *** > >On 20-04-01 at 12:35 David Robley wrote: > >>On Fri, 20 Apr 2001 12:19, Marcus Rasmussen wrote: >>> Hello. >>> >>> My question is: >>> How do I detect if mysql_connect() failed when I'm surpressing the >>> error message with @ like $linkid = >>> @mysql_connect("host","user","pass"); >>> And how do I, if it failes, get the error message? >>> >>> The manuel says that it: >>> [quote]Returns a positive MySQL link identifier on success, or an error >>> message on failure.[unquote] >>> >>> In my mind I should be able to detect if it returns an errormessage >>> like this: if(!$linkid) >>> $error = mysql_error(); >>> or: >>> if(!is_int($linkid)) >>> $error = mysql_error(); >>> Noone of theese 2 types works :-(. >>> I'm using is_int() because the manuel says that mysql_connect() returns >>> an int. (How can it then return an error message? I thought that an >>> error message would be some kind if string :-).) >>> >>> Here comes another problem, when an error occours I should be able to >>> see the message with mysql_error() (since the linkid not contains an >>> error message.) >>> >>> Marcus R. >> >>Try testing the value of mysql_errno() and echo mysql_error accordingly. >> >>-- >>David Robley| WEBMASTER & Mail List Admin >>RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ >>AusEinet| http://auseinet.flinders.edu.au/ > >Flinders University, ADELAIDE, SOUTH AUSTRALIA >> -- +-- KDVS 90.3fm Annual Fundraiser : 16 - 22 April 2001 --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +- www.kdvs.org -+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] INI file parsing
AFAIK, it will reread the .ini file every time only if you're running PHP as a CGI, as opposed to an Apache module (or ISAPI or NSAPI module, but I don't think either of those are industrial strength yet). SO, yes, the .ini file will be reread each time PHP is called by IIS. -steve At 01:02 PM 1/2/02 , Joe Webster wrote: >If so that would be totally shitty (in the respects of effecienty) > > >"Charlesk" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > I am running IIS 5.0 Windows 2000 Server. Changes made to the ini take >effect immediately. So it seems that php in Windows and IIS reloads the ini >every time a page is requested? > > > > Charles Killmer > > > > -- Original Message -- > > From: "Joe Webster" <[EMAIL PROTECTED]> > > Date: Wed, 2 Jan 2002 15:46:32 -0500 > > > > no you need to restart apache to change an in setting. So it loads the > > settings once per server start (at least with apache). > > > > "Charlesk" <[EMAIL PROTECTED]> wrote in message > > news:<[EMAIL PROTECTED]>... > > > Does PHP parse the ini file every time a file is requested? I am trying > > to track down a problem on various pages where the timelimit will expire. > > These are not complex pages and when I go to them they work fine. > > > I have used the same browser that the user eses when the timeout occurs. > > Nothing strange for me. > > > I have looked at the line that the error log specifies and it is just > > random lines. sometimes it is a '}'. As if the script just ran out of >time > > on that line. BTW '}' is the closing of an if statement so it isnt stuck >in > > a loop. And when I go to the page I make sure to use the same querystring > > that the user sent. > > > > > > Another thought, is the php engine slowed by users with a slow >connection? > > > > > > Charles Killmer > > > NetgainTechnology.com > > > > ++ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] string to array??
Actually, you can treat a string as an array without any further processing: $Globbot = 'dribcot'; echo $Globbot[0]; # echoes 'd' echo $Globbot[6]; # echoes 't' Check out 'String access by character' about halfway down the page at http://www.php.net/manual/en/language.types.string.php (or, in Portuguese, http://www.php.net/manual/pt_BR/language.types.string.php ). Actually, using the [] syntax is deprecated - using {} is the new way - but I'm a creature of habit... -steve At 11:57 AM +0100 1/17/02, Nick Wilson <[EMAIL PROTECTED]> wrote: >-BEGIN PGP SIGNED MESSAGE- >Hash: SHA1 > > >* On 17-01-02 at 11:46 >* Sandeep Murphy said > >> hi, >> >> can i convert a string to an array?? if so how shud the syntax read?? >> >> Thnx, >> >> sands >> > >Check out explode() >www.php.net/manual/en/function.explode.php > >- -- > >Nick Wilson > >Tel: +45 3325 0688 >Fax: +45 3325 0677 >Web: www.explodingnet.com > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] string to array??
Sorry if I was less than totally clear; I was referring to this part of the page: Characters within strings may be accessed by specifying the zero-based offset of the desired character after the string in curly braces. Note: For backwards compatibility, you can still use the array-braces. However, this syntax is deprecated as of PHP 4. Example 6-3. Some string examples /* Get the first character of a string */ $str = 'This is a test.' $first = $str{0}; ...and that was the first I'd noticed that myself; I assume that the {} syntax is only being used to refer to arrays as strings, to avoid confusion with an array of strings - $str = array('string 1', 'thing 2'); echo $str[0]; # produces 'string 1' - and a scalar string variable being treated as an array of characters. So I'm guessing (too lazy to test right at the moment) that you would get $str = array(array('bork','fubar'), 'snafu'); echo $str[0][1]; # produces 'fubar' echo $str[1][1]; # produces null echo $str[1]{1}; # produces 'n' Again, that's just what I'm assuming from the docs. A quick test would clear it up, but it doesn't affect me right now, and I'm feeling lazy ;) Hope that clears up my statement... -steve At 12:11 PM -0500 1/17/02, Erik Price wrote: >I didn't know that either. Does this apply only when accessing >strings by character? Or are all conventional uses of brackets >deprecated for the purposes of arrays? > >It doesn't say on that page >(http://www.php.net/manual/en/language.types.string.php , a bit more >than halfway down). > > >Erik > >> >>>Actually, using the [] syntax is deprecated - using {} is the new way >>>- but I'm a creature of habit... >>> > > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: Any Ideas
Or do it all in one line: $string = ereg_replace('[!@#$%^&*()_+=-';:"/.,<>?]', '', $string); If you want to remove non-alphanumeric characters from a string, you can do: $string = ereg_replace('[^[:alnum:]]', '', $string); Perl-compatible regular expressions would work as well, and be slightly faster. For more info, see: http://www.php.net/manual/en/function.ereg.php http://www.php.net/manual/en/ref.regex.php http://www.php.net/manual/en/ref.pcre.php -steve At 12:21 PM -0800 1/26/02, "qartis" <[EMAIL PROTECTED]> wrote: >I'm guessing something along the lines of: > >-- >$string=str_replace("!","",$string); >$string=str_replace("@","",$string); >$string=str_replace("#","",$string); >$string=str_replace("$","",$string); >$string=str_replace("%","",$string); >$string=str_replace("^","",$string); >-- > >etc. > >"Philip J. Newman" <[EMAIL PROTECTED]> wrote in message >003d01c1a6a5$fa7d60e0$0401a8c0@philip">news:003d01c1a6a5$fa7d60e0$0401a8c0@philip... >Any Ideas how I can remove !@#$%^&*()_+=-';:"/.,<>? charactors from a >string? > >Philip J. Newman >Philip's Domain - Internet Project. >http://www.philipsdomain.com/ >[EMAIL PROTECTED] >Phone: +64 25 6144012 -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Book database (slightly OT)
Perhaps the Library of Congress?? http://www.loc.gov/z3950/ You could hack the web interface, but it would be more efficient to query the database directly using the Z.39.50 stateful protocol: see http://lcweb.loc.gov/z3950/gateway.html#about and http://www.niso.org/standards/resources/Z3950_Resources.html among other places. You could probably write a pretty decent interface using PHP's socket functions, but it would be more efficient to write a PHP extension for it - depending on how intense your searches were. That was on my to-do list for a project a few years ago, but I'm no longer working on that. -steve At 4:32 PM -0500 1/29/02, Reuben D Budiardja wrote: >Hi, >I am working on a projects for book cataloging. What I want to do is to input >all the books isbn to a mysql table, either by hand or by scanning it, and >then let php go through those data and add more info such as tittle, author, >publisher, etc. > >Now, the real question is, does anyone know is there any database / services >out there that I can query using isbn, that will return me a parse-able info >for this purpose? >I am looking for service that is free, if possible, since this project is not >for commercial at all (academic purposes). > >Any information on this will be greatly appreciated. > >Thanks. >Reuben D. Budiardja > -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Ports
Well, a quick google - http://www.google.com/search?hl=en&q=tcp+ports - gave me: http://www.networkice.com/advice/Exploits/Ports/ and http://www.iana.org/assignments/port-numbers This would presumably be the authoritative source; the answer to your questions is at the top of this (very long) page. -steve At 04:20 PM 2/4/02 , Liam MacKenzie wrote: >Just a quick question... >What is the highest port possible? > >I want to make a PHP port scanner, but need to know the portrange. > >Thanks +--------+ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+
Re: [PHP] Using a mysql data base and cookie to log a person in
Have you considered PHPLIB? http://phplib.sourceforge.net/ http://sourceforge.net/projects/phplib http://www.sanisoft.com/phplib/manual/ The docs'll give you an idea of how they did it. The code is pretty complex, though, but it does a lot. I'd suggest using this as a base, if PHP4's session handling isn't sufficient. I use it, with my own hacks for my authorization needs. -steve At 8:38 AM -0800 2/20/02, Brandon Orther wrote: >Hello, > >I loosely understand how I can have a person login to a system by giving >them a cookie with a certain amount of time with a encrypted code. And >save that same encrypted code in the database for a certain amount of >time. I am looking for a tutorial on how to do this so I can wrap my >mind around it a little better. > >If anyone knows a good tutorial on how to log people into your site >using a userser database please hook me upZ wiT da Inf0z > >Brandon Orther >WebIntellects Design/Development Manager [EMAIL PROTECTED] >800-994-6364 >www.webintellects.com > > -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] viewing get/post variables
You might be thinking of the register_globals parameter here, instead of safe_mode: http://php.he.net/manual/en/configuration.php#ini.register-globals It is, in general best to keep this off so that you can explicitly validate user input. If you trust the POST or GET data, though, you can turn register_globals ON or use the extract() function - http://php.he.net/manual/en/function.extract.php - for example: extract($HTTP_GET_VARS); echo $var1; or in a function, extract($GLOBALS['HTTP_GET_VARS']); echo $var1; I don't think the safe_mode setting affects this, but I'm not sure. Some of the default settings may have changed between 4.0.6 & 4.2; that might explain why behavior changed after upgrading. -steve At 10:43 AM -0300 4/16/02, Martín Marqués wrote: >On Mar 16 Abr 2002 10:35, Christoph Starkmann <[EMAIL PROTECTED]> wrote: >> Hi Martín! >> >> > I can't remmeber how to configure php.ini so that if I get the URL >> > http://localhost/index.php?var1=10 >> > an echo $var1 will return 10 >> > What I mean, is that _GET["var1"] exists, but I want $var1 to >> > be available. >> >> If $var1 is not available directly, your safe_mode seems to be >> turned on. >> One way would be to turn safe_mode off again: change the line >> >> safe_mode=On >> to >> safe_mode=Off > >safe_mode is Off. > >> in your php.ini. >> >> The safer way would be to prepare $var1, for example like this: >> >> $var1 = $HTTP_GET_VARS["var1"]; >> >> Now you can use $var1. > >Before I upgraded PHP form 4.0.6 to 4.2.0RC2 it worked directly, without >having to pass the $HTTP_GET_VARS. > >Saludos... :-) > >-- >Porqué usar una base de datos relacional cualquiera, >si podés usar PostgreSQL? >- >Martín Marqués |[EMAIL PROTECTED] >Programador, Administrador, DBA | Centro de Telematica >Universidad Nacional > del Litoral >- -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "If only life would imitate toys." | | - Ted Raimi, March 2002 | | - http://www.whoosh.org/issue67/friends67a.html#raimi | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re:phpinfo
You might want to take a look at: http://www.php.net/manual/en/ref.info.php Specifically, get_cfg_var(), ini_get(), and ini_get_all() -steve At 10:08 AM -0700 5/23/02, Dennis Gearon wrote: >What I was trying to do was to find out how to get magic_quotes_sybase >config value. This will do it: > $test = addslashes("'"); > $this->sybase_magic = strcmp( $test, "\\'"); > >Also, I looked up eval(), it doesn't return the output of all fucntions >like I thought. I would have to use system, the backticks, invoke php as >a one time interpreter, OR, have a page that I call that has the >appropriate version of PHPINFO in it, and call that page and process the >returned call, from with in the current script. > >Dennis Gearon <[EMAIL PROTECTED]> wrote: >-- >>has anyone tried to eval() php info to prevent it from being displayed >Lso it could be processed for config checking, instead? >> >>Since what version have the 'subsections' of phpinfo() been available, >>like >> phpinfo(INFO_CONFIGURATION); ? >>-- >-- > >If You want to buy computer parts, see the reviews at: >http://www.cnet.com/ >**OR EVEN BETTER COMPILATIONS**!! >http://sysopt.earthweb.com/userreviews/products/ > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "If only life would imitate toys." | | - Ted Raimi, March 2002 | | - http://www.whoosh.org/issue67/friends67a.html#raimi | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making varibles (more than one) with a function.
Because global is specific to the SCOPE not to the variable - variables themselves aren't tagged as global. If you add global $text; in your echoo() function it will work. Alternatively, you could replace echo $text; with echo $GLOBALS['text']; in your echoo() function. See http://www.php.net/manual/en/language.variables.php for more info. -steve At 3:17 PM -0600 5/23/02, David Duong wrote: >If that works than the why does test file I tried previously to making the >post return a $text does not exist error? >echoo(); > >function test() { >$text = "Testing"; >global $text; >} > >function echoo() { >test(); >echo $text; >} > >?> > >"Sqlcoders.Com Programming Dept" <[EMAIL PROTECTED]> wrote in message >009f01c20241$f05aaf80$6520fea9@dw">news:009f01c20241$f05aaf80$6520fea9@dw... >> Sqlcoders.com Dynamic data driven web solutions >> >> - Original Message - >> From: "David Duong" <[EMAIL PROTECTED]> >> To: <[EMAIL PROTECTED]> >> Sent: May 22 2002 04:21 PM >> Subject: [PHP] Making varibles (more than one) with a function. >> > I am aware that return can return strings but is their a set global or a >> > function similar to return? >> >> hi there!, >> There sure is, it's called global. >> Usage: >> global $variable_a; >> global $variable_b; >> global $variable_c; >> ... >> >> HTH, >> Dw. >> > > > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "If only life would imitate toys." | | - Ted Raimi, March 2002 | | - http://www.whoosh.org/issue67/friends67a.html#raimi | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] running commands as root from a script
I have done a similar thing by executing another script via sudo using the PHP command passthru() (or you could use exec(), system(), whatever's appropriate). See http://www.courtesan.com/sudo/ for more info. The whole setup was (and is) a bit of a kluge, but the script didn't need to be run often so it doesn't impact server performance any. -steve At 09:37 AM 3/28/02 , Ken Nagorski wrote: >Hi there, > >I have a little problem. I need to run a few commands for Courier from a >script. What I have is a php based application that makes it easy to create >and manage virtual domains and the addresses for them from the web. However >when You "Apply the changes" everything is written to /tmp dir and the a >little perl script parses the file and moves things where they need to go >and then runs couriers makealiases command. Now you can't run a perl script >SUID so I wrote a C program that just calls system() and runs the script and >it is SUID. This doens't work however. No matter what I do. It is like >Courier ignores this. > >I can't imagine there isn't anyone who has not run into the problem of >automating things via PHP and not had to run a system command as root at >some point in time. I am wondering what the different approaches to this >problem are. > >Thanks >Ken > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php ++ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arguments against php / mysql?
Other people have made similar arguments, but just thought I'd throw in my 2c: I had a couple of years experience running MySql (3.22.something) on WinNT4sp5, 3-4 years with PHP as a CGI (going all the way back to PHP2 aka PHP/FI) and ~9 months using Apache/PHP on Windows. As of last fall, I have no Windows machines anymore, so my recollection at the moment of details/versions is a bit fuzzy. At 5:30 PM +0100 4/10/02, Mallen Baker wrote: >Hi - the company we're talking to about doing some work on a simple >site / database is trying hard to persuade us that Windows-based PHP >/ mysql is not the route to go. The arguments are as follows: > >1. XXX's experience that MySQL is less than 100% stable when running >on a windows platform (main problem being unexpected database >shutdowns while applications are being used). While I had fairly modest database usage, I NEVER had a single problem with MySQL/Windows. It was fast, took up very little memory, was about as close to set-and-forget as I've seen. >2. The fact that the recommended mode for running PHP on a windows >platform (the CGI binary) uses technology that is now reasonably old >and will consequently result in a hit to the server performance and >memory management and the associated possible lack of scalability. As others mentioned, this is obsolete info; I migrated sites running on Netscape Enterprise 3.5 & IIS to Apache with the PHP module (I believe the versions were 1.3.20 & a fairly early PHP4) with few problems (the biggest of which were a few functions that didn't work as expected in a PHP release candidate, but there were simple workarounds and - well, it was a release candidate not a final release). I used the PHP modules from PHP4WIN: http://www.php4win.de/ By the way, the Apache/PHP-based solution worked much better than the ColdFusion stuff I was running on the same server. Cold Fusion sucked up tons of RAM, and on occasion database queries on an Access database caused CPU usage to spike at 100% until I restarted the CF server. If you want to use PHP with IIS, then it is my (likely obsolete & incorrect) understanding that the PHP ISAPI version is still somewhat experimental, and that CGI is the recommended approach there. But then, I would avoid IIS as a web server to begin with. >3. Loss of verity - the powerful search engine bundled with Cold >Fusion. Searches may be significantly slower on the new site. I'm sure you could still use Verity, but yes - you'd have to purchase it separately. I had just started using htDig - http://www.htdig.org/ - as a search engine on the Windows box, but I didn't get much of a chance to get production experience with it. There's also MnoGoSearch - http://www.mnogosearch.ru/ - which looks promising (and is pretty popular on the Unix side), but I don't have any experience with it. And, I think there's some nominal license fee to use it on Windows. Thus endeth my spiel - - steve edberg -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "If only life would imitate toys." | | - Ted Raimi, March 2002 | | - http://www.whoosh.org/issue67/friends67a.html#raimi | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Set Global Variables
Well, on unix, you could use the (still experimental, according to the docs) shared memory functions: http://php.he.net/manual/en/ref.shmop.php There's also the apparently more mature, but less portable semaphore/shared memory functions (also Unix only) here: http://php.he.net/manual/en/ref.sem.php I've never used either of these. Maybe you could explain what you're trying to do a bit more (and what platform you're on). I can't see where loading separate copies of the variables would be much of a memory issue, unless you have large numbers of variables, very long strings stored there, and hundreds of apache child processes. - steve At 2:52 PM -0400 4/11/02, [EMAIL PROTECTED] wrote: >If I do that, won't the data that I fetch be duplicated in memory for each >user? I'm trying to have just one space in memory allocated for these >variables, sort of like the HTTP_SERVER_VARS. It seems that even if I do an >autoprepend that file is going to run each time a user visits the site and a >new memory space will be created for that variable. What I'm asking is how >to set those constant server-wide global variables. > >Thanks >Roger > >-Original Message- >From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]] >Sent: Thursday, April 11, 2002 10:15 AM >To: [EMAIL PROTECTED] >Cc: [EMAIL PROTECTED] >Subject: Re: [PHP] Set Global Variables > > >Set up an auto_prepend file that either simply sets these constant globals >ot fetches them from the DB. > >-Rasmus > >On Thu, 11 Apr 2002 [EMAIL PROTECTED] wrote: > >> Is there a way to set a global variable that all users can access? I have >> some values in a database that I'm reading at the beginning of the session >> and carrying through out the session. The thing is, those values are the >> same for every user and instead of having a memory space for each users >> values I'd rather just use one memory space for all users. >> >> Thanks >> >> Roger Ramirez >> Web Developer > > LifeFiles.com Inc. >> -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "If only life would imitate toys." | | - Ted Raimi, March 2002 | | - http://www.whoosh.org/issue67/friends67a.html#raimi | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Access $HTTP_POST_VARS from class member fucntion
At 10:41 AM -0800 11/4/01, Daniel Harik wrote: >Hello > > I have a class called Member, it has member function called > vallidateForm(), i try to pass it a $HTTP_POST_VARS array it looks like this: > > >clas Member{ >var $HTTP_POST_VARS; >function vallidateForm ($HTTP_POST_VARS){ > echo $HTTP_POST_VARS['frmUsername']; >} >} Syntax here is wrong; you don't need to declare function arguments using var; only class variables need that. I'm uncertain what will happen if you do this. I would expect that - if PHP's error reporting were turned up to the maximum - it might give you a warning message. So do either: (1) Drop the 'var $HTTP_POST_VARS line; OR do (2) clas Member{ var $HTTP_POST_VARS; function vallidateForm (){ echo $this->HTTP_POST_VARS['frmUsername']; } } Although option (2) would require rewriting the code below. Also I assume that the 'clas Member{' line is just a typo, and your actual code says 'class Member{'... >$user = new Member; >if($action=="register"){ >global $HTTP_POST_VARS; >$user->vallidateForm($HTTP_POST_VARS); >}else{ >$user->displayForm(); >} >?> > >But i can't acces $HTTP_POST_VARS['frmUsername'] within the function > If you are using an old (any PHP3.x, and I think some early betas of PHP4) version of PHP, you need to turn 'track_vars' on to enable $HTTP_POST_VARS and other $HTTP_xxx_VARS arrays. If that's the case - and you can't upgrade immediately - you need to turn track_vars on in httpd.conf, php.ini, or .htaccess (whatever's appropriate in your setup). Hope that helps - - steve edberg -- +--- my people are the people of the dessert, ---+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | + said t e lawrence, picking up his fork + -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Image width??
http://php.he.net/manual/en/function.getimagesize.php At 9:46 PM + 11/29/01, cosmin laslau wrote: >Hi, > >Is there any function or command in PHP that will return the width >an image (GIF)? > >Thanks. > -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Reg ex help-Removing extra blank spaces before HTMLoutput
One way to do it is: $NewString = ereg_replace('[[:space:]]+', ' ', $String); There are also ways to do it with preg functions that are slightly more efficient; see the pcre docs. And, the standard (AFAIK) reference book for regular expressions is O'Reilly's 'Mastering Regular Expressions'; a worthwhile purchase. -steve At 2:06 AM -0500 12/5/01, Ken wrote: >I want to remove all superfluous blank spaces before I sent my HTML >output, to make the output smaller. > >So I'd like to take $input, replace any number of blank space or >newlines that are consecutive and replace them with a single blank. > >I.e. I will list a blank space as b and a newline as n: > >If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE >Then output should be: bTEXTHEREbMOREbEVENMORE > >I imagine this would be handled by a simple regular expression call, >but I'm no pro with them yet. > >Any help? > >Thanks, >Ken >[EMAIL PROTECTED] > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] last entry in mysql
This may be stating the obvious, but: (1) Does your table have an auto_increment column? (2) If so, did a previous query in the program - for example, an INSERT - generate a new record with an auto_incremented value? AFAIK, mysql_insert_id() won't return the last id unless you have a previous query in that same program that INSERTED/UPDATED an auto_incremented column. If you want the maximum value of the column, you can always issue the query: SELECT max(your_auto_incremented_column_name_here) FROM your_table_name_here At 10:30 AM -0600 12/12/01, Yoed Anis wrote: >hey guys, > >quick question I'm having trouble finding an answer too. >In a mysql database, how can I select that last row entry. This might be >done mins after i put that entry there and i tried to use: > $lastid=mysql_insert_id(); to get the last id but to no avail. > >Thanks >Yoed > -- +----+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] phplib???
http://phplib.sourceforge.net/ At 4:59 PM -0500 12/13/01, Duane Douglas wrote: >hello, > >can someone please explain phplib to me? what is it used for? i >apologize if this question has been asked many times before. > >thanks in advance. > -- +--------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] $PHP_SELF not working -please help
Is the code below in a function? If so, you'll have to globalize $PHP_SELF: function your_function() { global $PHP_SELF; ... echo $PHP_SELF; .. } alternatively, you could do function your_function() { ... echo $GLOBALS['PHP_SELF']; .. } To the best of my knowledge, PHP_SELF is set regardless of the register_globals configuration setting, but I'm not 100% sure. -steve At 11:13 AM + 12/19/01, Caleb Carvalho wrote: >Hi there, > >I have created a script that is suppose to get some input from >user and display back, and i have the following method > > > >so i have a script that if login fails it will ask the user >to register, > > >if(!$username) { > session_unregister("userid"); > session_uregister("userpassword"); > echo "Authorisation Failed." . > "you must enter a valid credentials.". > "try again.\n"; >echo "Login"; >echo "If you're not a member please regsiter.\n"; >echo "Membership"; >exit; >} >else echo "welcome, $username!"; > > >Now for some strange reasons it tries to access my web direcorty >that does not contain any file, and i get the 404 page not found >error. > >any help would do, > >Thanks > >Caleb > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP3 NOT being parsed for SSI!! HELP!!
If you're using PHP as an Apache module, you can use virtual() - http://www.php.net/manual/en/function.virtual.php - to include the dynamic parts; vcstatic includes could be handled by virtual() or just a normal PHP include()/require(). - steve At 11:09 PM -0800 12/19/01, Thomas Edison Jr. wrote: >Folks, > >I have a serious problem and i don't know what to do. > >We have a fixed template for each intranet page. >Now the template consists of a header, a left >navigation and a footer. The body would contain >my pages content. > >What we are doing at present is that the header, the >left navigation and the footer is included in the page >using SSI. The header is a static include file. >However the footer and the left navigation are >customizable, and hence are dynamic pages (cgi >scripts) which generate the appropriate code depending >on the command line parameters. > >Now the problem is that php3 pages are not being >parsed for SSI. I looked up on the web , and >found that only one of two can be used at the same >time. > >Can anyone suggest a Possible Solution? We are running >a Solaris machine! > >Thanks, >T. Edison Jr. > >= >Rahul S. Johari (Director) >** >Abraxas Technologies Inc. >Homepage : http://www.abraxastech.com >Email : [EMAIL PROTECTED] >Tel : 91-4546512/4522124 >******* > -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us."| | - Supreme Court Justice (1939-1975) William O. Douglas | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Number Format
Or http://www.php.net/manual/en/function.sprintf.php or http://www.php.net/manual/en/function.printf.php At 04:45 PM 12/20/01 , Bogdan Stancescu <[EMAIL PROTECTED]> wrote: >if ($i<10) { $i="0".$i } ? :-) > >phantom <[EMAIL PROTECTED]> wrote: > > > I would like to format numbers to be a fixed width. > > > > I want all numbers to be 2 characters in width to the left of the > > decimal point. > > > > 1 should be 01 > > 2 should be 02 > > 3 should be 03 > > > > How can I do this? > > ++ | Steve Edberg [EMAIL PROTECTED] | | Database/Programming/SysAdmin(530)754-9127 | | University of California, Davis http://pgfsun.ucdavis.edu/ | +-- Gort, Klaatu barada nikto! --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Question: Number of Characters
At 4:16 PM -0700 4/1/01, Marcus Ouimet wrote: > How can i determine the number of characters in a string? I >am using substr >to cut off the last 4 characters of a string. Which is working great. But I >want to replace the 3 charcters with "..." only if there are over 20 >charcters . I tried substr_replace but it appears on everything no matter >how many characters. I am trying to do this is simple terms: Use strlen(). For example: $String = 'hi my name is'; if (strlen($String) > 20) { $String = substr($String, 0, 17).'...'; } In PHP4, you can use the substr_replace() function to replace the third line in the example above: $String = 'hi my name is'; if (strlen($String) > 20) { $String = substr_replace($String, '...', 17); } For more information, see http://www.php.net/manual/en/function.strlen.php http://www.php.net/manual/en/function.substr.php http://www.php.net/manual/en/function.substr-replace.php -steve >if the string was: > >hi my name is > >it is returned shortened to: > >hi ... > > Any help appreciated. > -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ereg
At 9:47 PM -0800 3/31/01, Chris Adams <[EMAIL PROTECTED]> wrote: >On 31 Mar 2001 21:07:59 -0800, Michael Hall <[EMAIL PROTECTED]> wrote: >> >>I'm using the following expression to check input strings: >> >>if (!ereg("^[[:alnum:]_-]+$", $string)) { get outta here! } >> >>This works fine except for when a string has spaces, as in text. What do I >>need to add to the expression to handle spaces (internal, not at the >>beginning or end). > >if (!ereg("^[[:alnum:]_- ]+$", $string)) { get outta here! } > >Check out the regular expression documentation or "Mastering Regular >Expressions" over at ora.com. > If by 'spaces' you want to include tabs, newlines & stuff, you can also do: if (!ereg("^[[:alnum:][:space:]_-]+$", $string)) { get outta here! } -steve -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] HTTP_POST_VARS
At 4:50 PM +0200 4/12/01, Dominick Vansevenant <[EMAIL PROTECTED]> wrote: >Mat, > >did you put in a reset? > >reset($HTTP_POST_VARS); > >D. Yes, you'll need the reset() there if you're looping through the $HTTP_POST_VARS array more than once. However: I take it that you were trying something like echo $HTTP_POST_VARS[0]; ? If so, you will indeed get the output 'array' if element 0 is an array. As someone suggested, you can use the print_r() or var_dump() functions (print_r, I think, is PHP4 only) to display it. You can also do something like ... if (is_array($HTTP_POST_VARS[0])) { while (list($k,$v)=each($HTTP_POST_VARS[0])) { echo '$HTTP_POST_VARS[0]', "[$k] = $v"; } } else { echo '$HTTP_POST_VARS[0] = ', $HTTP_POST_VARS[0]; } ... In PHP3, POST/GET elements could only be one dimensional arrays, at most. In PHP4, though, these can have 2+ dimensions, so for maximum generality you'd have to have somewhat more complex code than this. -steve >-Original Message- >From: Mat Marlow [mailto:[EMAIL PROTECTED]] >Sent: donderdag 12 april 2001 16:49 >To: [EMAIL PROTECTED] >Subject: [PHP] HTTP_POST_VARS > > >Hi all, >I'm having trouble retrieving data from $HTTP_POST_VARS. Whenever I try to >print something from it using print($HTTP_POST_VARS[0]); it just prints >"Array". And I know it works because I've done it once and can't do it >again! >Am I missing something glaringly obvious? > >Thanks for the help, > >Mat >PS. track_vars is ON! > -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Fetch_row
At 2:17 AM + 4/13/01, Mike P wrote: >Can I use Mysql fetch_row to specify which row i want to get? >Like---$row[5]=mysql_fetch_row($result) ? >Mike P >[EMAIL PROTECTED] > Are you talking about a specific row in the mySQL result set? If so, use the mysql_result() function. However, this function only returns one column at a time, so you'd have to loop, something like: $i=0; unset($row); while ($Value = mysql_result($ResultId, 4, $i)) { $row[] = $Value; $i++; } Note I used row # 4 in the mysql_result() call instead of 5, since (I'm 89% sure) row counts are 0-based. I'm also pretty sure you CANNOT use mysql_result() to position to the desired row, then use mysql_fetch_array() or a similar function to fetch the whole row. See http://www.php.net/manual/en/function.mysql-result.php for more info. You may be able to use the mysql LIMIT functionality to do what you want: $Query = 'SELECT * FROM table ORDER BY name LIMIT 4,1'; This grabs the fifth (again, row counts are 0-based) row. See http://www.mysql.com/doc/S/E/SELECT.html Incidentally, your original statement $row[5]=mysql_fetch_row($result); would simply create a 1-element array $row, with the array index 5. If this was your first fetch statement, $row[5] would still contain the first row of the result set. -steve -- +--- 12 April 2001: Forty years of manned spaceflight ---+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- www.yurisnight.net --+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] bad form...
As far as I know, there are no ill effects from doing this; I do it all the time. In the FORM tag, I can then use something like action="$PHP_SELF" or action=$HTTP_SERVER_VARS['PHP_SELF'] (I have the top form on a PHP3-based setup). On the occasion when I need to redirect the user to another page (after a successful login or registration), I can use a header("Location: somewhere.else/to/go.html") line. -steve At 8:12 PM -1100 6/19/01, motorpsychkill wrote: >hello everyone, is it 'bad form' (no pun intended) to have a form point to >itself for processing, rather than forward the form variables to another >page? Anybody have any input on this? I try to have 1 page that is the >form and handles all the processing as well in order to keep the page count >on my site low and for easier editing, blah blah blah > >thank you for you help! -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+
Re: [PHP] PHP3
The PHP version plays no part in this, since the SELECT statement below is passed directly to MySQL. And, yes, this should work on that MySQL version - it's a pretty simple statement. Were you experiencing a problem with it? If so, post the relevant PHP code & the error message you're getting. The only thing that might conceivably be a problem is the table alias syntax. What you have _should_ work, but you could also try Select a.field, b.field from table_one AS a, table_two AS b where a.id = b.id - steve At 1:48 PM -1000 6/20/01, William Poarch wrote: >Hi, > >Does "Select a.field, b.field from table_one a, table_two b where a.id = >b.id" work in PHP3/MySQL 3.22.32? > >Client's running PHP3, and I'm on 4. > >thanks. > - - - - - - - - - - > Scott Poarch > www.globalhost.com > - - - - - - - - - - -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Filtering out \ when a ' is user entered?
See www.php.net/stripslashes Also check out the PHP configuration settings for magic_quotes_gpc -steve At 9:18 PM -0700 6/26/01, Marcus James Christian wrote: >Hello, > >I'm pretty new to PHP but all I've seen of it so far I pretty much love! > >I've built a web log but when the user enters their data and they use ' >or " (and you know they will) php always shows it from the included >web log as > >\' How can I filter out these backslashes so they don't appear on the >final public viewable page? > >Thanks, >Marcus >-- >Marcus James Christian - UNLIMITED - >Multimedia Internet Design >http://mjchristianunlimited.com -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split() function
You don't need a character class here (signified by [] brackets); you can use $line = split('&|//', $field); As you can see, this is identical to ReDucTor's solution, except that the brackets are omitted. Character classes only work for single characters, not multiple character strings like '//'. - steve At 3:21 PM -0400 7/4/01, David A Dickson wrote: >Thanks for replying ReDucTor but that didn't work either. I tried >$line = explode("[(&|//)]", $field); and >$line = explode("[(&|)]", $field); and >$line = explode("[(&|\/\/)]", $field); >with no success. Any other ideas? > >On Thu, 5 Jul 2001 04:50:29 > ReDucTor wrote: >>$line = explode("[(&|//)]",$field); should work, or you might have to put >> but thats not \ so you shouldn't need to comment out the slash... >>- Original Message - >>From: David A Dickson <[EMAIL PROTECTED]> >>To: php-general <[EMAIL PROTECTED]> >>Sent: Thursday, July 05, 2001 4:37 AM >>Subject: [PHP] split() function >> >> >>> I have a comma separated spreadsheet with one field that contains two >>dates. the dates are formatted as dd/mm/yy and separated by either '&' or >>'//' ex:3/12/92&28/1/93 or 3/12/92//28/1/93 >>> Problem: I need to split the field at the '&' or '//' separator but if I >>do > >> split('[&//]', $field); >>> it splits on the '/' not the '//'. >>> Can I do this in one function call to split() or will I have to do it >>twice? > > > >Get 250 color business cards for FREE! >http://businesscards.lycos.com/vp/fastpath/ > >- End Forwarded Message - -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Missing first record in PHP/Mysql query
At 7:11 PM -0700 7/5/01, Rory O'Connor wrote: >Excuse me if this is too newbie...but I'm writing a simple script to >query a database and loop through the reuslts, echoing them on the page. > When I enter the query at the mysql command line, I get the correct >results. But the same query run through PHP renders all results except >the first one. Any idea why? It's doing exactly what you told it to ;) See below: >I've included the code snippet below: > >//the query to select the data >$query = "SELECT firstname,email,optin from contact where >interest='rory'"; >$result = mysql_query($query); >if(!$result) error_message(sql_error()); > >$query_data = mysql_fetch_row($result); This line fetches the first row and moves the pointer to the next row. You then proceed to ignore the results of the first row! Just delete this line, and you'll be happy. >while($query_data = mysql_fetch_array($result)) { > $firstname = $query_data["firstname"]; > $email = $query_data["email"]; > $optin = $query_data["optin"]; > > echo "\n"; > echo "$firstname;$email;$optin\n"; > >} //end while loop > >also, what would be the code to output the reuslts to a text file >instead of (or in addition to) the screen? Check out the file functions - fopen, fwrite, fclose will be of particular interest: http://www.php.net/manual/en/ref.filesystem.php >thanks, > >rory > >providing the finest in midget technology > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: string formatting help
In the original message below, did you mean that you're actually SEEING the tags in the output? If so, there may be a conversion with htmlentities() going on somewhere that converts the tags to <br> (so they are displayed instead of being interpreted). If you replaced the 's with spaces or newlines, the output _should_ all be on one line, since HTML considers ALL strings of whitespace (tabs, newlines, returns, spaces) to be a single space. If you replaced 's with newlines and you are getting the line breaks still, your output may be in a ... block. - steve At 3:36 PM -0300 7/6/01, "InÈrcia Sensorial" <[EMAIL PROTECTED]> wrote: > Maybe: > >$array = explode("", $string); > >foreach ($array as $key => $value) { > echo "$value"; >} > > Would separate the string by 's and print all in one line. > Or, more compactly: echo str_replace('', '', $string); This would only work if tags were lowercased; to handle mixed case, you'd need to do echo eregi_replace('', '', $string); or use the preg equivalent > Julio Nobrega. > >A hora est· chegando: >http://sourceforge.net/projects/toca > >"Chad Day" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >> I'm trying to pull a string from a database to use in a javascript >> function.. but it's doing line breaks on me, which in turn messes up the >> javascript. >> >> The string in the mysql db is like: >> kjdsakjadkskjdkskjkdfjdfkjfd >> >> When I pull it out, it becomes: >> >> kjdsakjadk >> >> skjdks >> >> >> kjkdfjdfkjfd >> >> I've tried replacing the br's with blank spaces or new line characters, >but >> in the html code it still breaks on those breaks when I echo it back out. >> How can I force this string to be all on one line? >> >> Thanks, > > Chad >> -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] foreach loop
At 10:31 AM -0700 7/7/01, John Meyer wrote: >When I go through a foreach loop, are the values of the individual >items in the array changed? >For instance: >$variables = array($author_firstname, $author_lastname, $author_dob, >$author_dod, $author_bio); > foreach($variables as $value) { > $value = strip_tags($value); > $value = AddSlashes($value); > } >will the values be changed outside of the loop? > No, because $value is a copy the current array element, not simply a pointer to it. Furthermore, if I understand the documentation (see below) correctly, this construct (using the $variables array from above) - $i = 0; foreach ($variables as $value) { $variables[$i] =AddSlashes( strip_tags($value)); $i++; } - will not work either, since foreach() operates a COPY of the array. From the docs at http://www.php.net/manual/en/control-structures.foreach.php : Note: When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. This means that you do not need to call reset() before a foreach loop. Note: Also note that foreach operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified as with the each() construct and changes to the array element returned are not reflected in the original array. - steve >John Meyer >[EMAIL PROTECTED] >Programmer > >If we didn't have Microsoft, we'd have to blame ourselves for all of >our programs crashing > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Name of an array???
Not quite sure what you're getting at here. As you discovered, if you have $Thing = array(5,6,7,8); and you 'echo $Thing;' you get 'Array.' However, in this case, you know the variable name already - $Thing! Are you thinking more along these lines: $ArrayName = 'Thing'; $$ArrayName = array(5,6,7,8); now, echo $ArrayName;==> Thing echo $$ArrayName; ==> Array echo ${$ArrayName}[0]; ==> 5 See http://www.php.net/manual/en/language.variables.variable.php for more info. -steve At 1:03 PM -0700 7/9/01, Dallas K. wrote: >I need to echo the NAME of an array to the browser. when I try >this all I get is "Array". when I try to : echo $$array_name; I >get nothing. > >How can I get the NAME of an array to the browser? > >Thanks. -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] sorting results of opendir()
Here's one way: $dir = opendir('.'); unset($FileList); while ($file=readdir($dir)) { if($file!= '.' && $file != '..') { $FileList[] = $file; } } sort $FileList; reset($FileList); while(list(, $F) = each($FileList)) { echo "$F\n"; } If you're using PHP4, you can replace everything after the sort($FileList) with the more compact: foreach($FileList as $F) { echo "$F\n"; } See http://www.php.net/manual/en/function.sort.php for more info on sorting arrays. - steve At 1:05 PM -0500 7/9/01, kmurrah wrote: >Greetings. > >I need to read the contents of a directory, sort it alphabetically, and >display it > >i'm doing find on the reading and displaying, but can someone help me with >the sort? > >$dir = opendir("."); > >while ($file=readdir($dir)) { > > > if($file!= "." && $file != "..") > { > echo("$file"); > } >} > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Help..Parse error
My guess is that you have the short_open_tags option on in your PHP3 config, but off in your PHP4 config. If it's off, PHP will only recognize the tags, not . PHP config params can be set in php.ini, .htaccess, and/or Apache httpd.conf files. Scroll down to short_open_tag in http://www.php.net/manual/en/configuration.php#configuration.file for more info. You can also check your config via the phpinfo() function. - steve At 1:45 AM -0400 7/20/01, Jack Sasportas wrote: >I have some code that runs under php3, but under 4 I get a parse error >on this specific line, can't figure out how to resolve it. > >the code looks like this > > > > >the error is in the middle line which is the end of a condition... > >Thanks in advance... > > >-- >___ >Jack Sasportas >Innovative Internet Solutions >Phone 305.665.2500 >Fax 305.665.2551 >www.innovativeinternet.com >www.web56.net > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Mysterious MYSQL Error..
Do you know if you've even made a valid database connection? Try echoing $this->database as well. If that is null, you haven't connected to your database; perhaps the username, password and or permissions were changed, so that you're unable to connect from your PHP program. - steve At 9:47 AM -0400 7/22/01, Greg Schnippel wrote: >I'm stumped on this one.. I set up PHP 4.04/Apache/Mysql 3.23 >on my Windows 98 box for development purpouses. Its been >working flawlessly for 2-3 years now (using the same >configuration files, etc). > >However, as of 3 days ago, i can't get it to execute a simple >"select * from table query". Here's the code I'm using: > >$query = "select * from $this->table where $this->primary_key='$record_id'"; >$result = mysql_query($this->database, $query); >echo mysql_errno().": ".mysql_error().""; > >and the query that it sends to the mysql database is > >"select * from article where article_id='1'"; > >However, mysql fails to execute the query. Result returns >nothing and the echo command returns: > >errno: 0 >mysql_error_text: "" > >??!? I've tried everything to get it to display any more information >as to why its breaking but nothing works. I even uninstalled and >reinstalled all of the packages, thinking it had something to do >with a windows dll file or something annoying like that but no luck. > >Any ideas? Anyone encountered a problem like this? > >Thanks, > >Greg > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Using $$ to access a variable
I'm not sure that your construct will work; however, you could always do echo $HTTP_POST_VARS[$table_array[$iCnt][0]]; in place of 'echo $$var' or $var = 'HTTP_POST_VARS'; echo ${$var}[$table_array[$iCnt][0]]; When using variable variables, the array index - here, 'ld_val' might not be interpreted correctly; I'm guessing that PHP is looking for a variable named 'HTTP_POST_VARS["ld_val"]', not an element of the HTTP_POST_VARS array. More info is at http://www.php.net/manual/en/language.variables.variable.php On the other hand, are you absolutely sure that something (other than whitespace) is actually IN $HTTP_POST_VARS['ld_val'] ?? - steve At 5:36 PM + 7/23/01, [EMAIL PROTECTED] wrote: >Please forgive my probably newbie question... >I am cycling thru my database using a SQL describe statement and then >am getting values from a form based upon the field name I find. This >is working up 'til I try to read the form data. > >I have defined a variable like this: > $var = $prefix.$table_array[$iCnt][0].$postfix; > >If I echo $var the printed result is: > HTTP_POST_VARS["Id_val"] > >This is perfect because I want to access a field on the submitted form >named "Id_val", but when I try echoing with a $$ like this: > echo $$var > >I get nothing. I was under the impression that I could access my >variable this way. Am I missing something basic here?? > >Thanks! > >Mark > -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]