[PHP] Getting Numerical Index of a Key
Is there an easy way to get the numerical index of a text key for an array? I don't see anything in the manual, but before I waste time writing code to find this info, I thought I would double check here. ---Matt
RE: [PHP] Getting Numerical Index of a Key
Because I created it with mysql_fetch_array(). I know for a fact that both keys exist, and I can look at the output and tell what text key matches to what numerical key, but I don't want to hardcode it like that. The people that are taking over this code might change something and screw everything up. ---Matt -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 12:35 AM To: Matt Honeycutt Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Getting Numerical Index of a Key What makes you think it HAS a numerical index? Matt Honeycutt wrote: Is there an easy way to get the numerical index of a text key for an array? I don't see anything in the manual, but before I waste time writing code to find this info, I thought I would double check here. ---Matt -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Getting Numerical Index of a Key
Bad design, basically. This script is creating the array, then modifying a certain value in it using the text key. Later, it's referring to each value in the array by numerical index. Apparently, the text key and the numerical index do not refer to the same values in PHP, so the value it's referring to with the numerical index is the original value, not the one that was modified. I'm just going to spend the extra 5 minutes and rewrite that little chunk of code. ---Matt -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 12:39 AM To: Matt Honeycutt Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Getting Numerical Index of a Key No, there's no easy way to do this. Just out of curiousity, why do you want to do this anyway? Matt Honeycutt wrote: Because I created it with mysql_fetch_array(). I know for a fact that both keys exist, and I can look at the output and tell what text key matches to what numerical key, but I don't want to hardcode it like that. The people that are taking over this code might change something and screw everything up. ---Matt -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 12:35 AM To: Matt Honeycutt Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Getting Numerical Index of a Key What makes you think it HAS a numerical index? Matt Honeycutt wrote: Is there an easy way to get the numerical index of a text key for an array? I don't see anything in the manual, but before I waste time writing code to find this info, I thought I would double check here. ---Matt -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] re: strip comma from $value
ereg_replace returns a string, regardless of whether or not any replacement occured. If no replacement occurs, the original string is returned. Additionally, it does not modify the original string, so you need to store the string it returns: foreach($numeric_array as $key = $value ) { if(strstr($value,,)) { $value = ereg_replace(,,,$value); echo comma stripped); } } Give that a shot and see if it works (I didn't test it, but it should). ---Matt -Original Message- From: Jim Long [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 11:42 AM To: php Subject: [PHP] re: strip comma from $value Hi, Trying this: //strip the commas from numeric array so it can sort properly--- foreach ($numeric_array as $key = $value) { if (ereg_replace (, , , $value)){ echo(comma striped); } } Does the same thing as before, echo's comma stripped, but does not actually remove the commas THANKS.. any other ideas? Jim Long -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] re: strip comma from $value
I hit send right as I saw a typo (the ')' in the echo statement. Should be this: foreach($numeric_array as $key = $value ) { if(strstr($value,,)) { $value = ereg_replace(,,,$value); echo comma stripped; } } -Original Message- From: Matt Honeycutt [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 11:56 AM To: php Subject: RE: [PHP] re: strip comma from $value ereg_replace returns a string, regardless of whether or not any replacement occured. If no replacement occurs, the original string is returned. Additionally, it does not modify the original string, so you need to store the string it returns: foreach($numeric_array as $key = $value ) { if(strstr($value,,)) { $value = ereg_replace(,,,$value); echo comma stripped); } } Give that a shot and see if it works (I didn't test it, but it should). ---Matt -Original Message- From: Jim Long [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 11:42 AM To: php Subject: [PHP] re: strip comma from $value Hi, Trying this: //strip the commas from numeric array so it can sort properly--- foreach ($numeric_array as $key = $value) { if (ereg_replace (, , , $value)){ echo(comma striped); } } Does the same thing as before, echo's comma stripped, but does not actually remove the commas THANKS.. any other ideas? Jim Long -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] re: strip comma from $value
I'm sorry, I missed a really big problem with what you're doing. When you use foreach(), the value that it gives you (in your case, via the $value variable) is not a reference to the array item, its a copy of it, so modifying the copy doesn't modify your original array. Use this (this should work): for($i=0; $i size($numeric_array); $i++) { if(strstr($numeric_array[$i],,)) { $numeric_array[$i] = ereg_replace(,,,$numeric_array[$i]); echo comma stripped; } } Give that a shot and see what happens... ---Matt -Original Message- From: Jim Long [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 12:00 PM To: php Subject: [PHP] re: strip comma from $value Hi, Thanks to those who are helping me. Matt, Same result, echo's sucess, but commas are still out put in the $numeric_array. Jim Long Matt Wrote: foreach($numeric_array as $key = $value ) { if(strstr($value,,)) { $value = ereg_replace(,,,$value); echo comma stripped; } } Hugh Wrote: try ereg_replace(,,,$value); Orignal post: Hi, I've figured out the way to solve my problem is to get rid of the commas before I sort. Trying to use this: //strip the commas--- foreach ($numeric_array as $key = $value) { if (stristr($value, ,)){ //test to see if it worked echo(comma striped); } } -- It passed the test but, I'm doing something wrong because the commas are still there. TIA, Jim Long Jim Long Wrote: Does anyone know how to make the flag sort_numeric work? Will it work with asort? asort ($numeric_array, SORT_NUMERIC); I've tried this but it looks like it's having problems with the comma in big numbers. I'm not absolutely sure, but it looks like it's ignoring everything after a comma when it sorts. BTW: asort is the one I need as I must maintain the keys JanetVal Wrote: sort() sorts by value but assigns new keys as numbers. asort() sorts by value, but keeps the same keys ksort() sorts by key. THANKS ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] problem in writing into an html text file
Check stripslashes(), I think that will help you. ---Matt -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED] Sent: Thursday, February 27, 2003 4:53 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] problem in writing into an html text file this code add a backslashes in all doubleqoutes in the html file. sample: before editing my.html file textarea name=message cols=95 rows=20 after editing my.html file textarea name=\message\ cols=\95\ rows=\20\ any idea why and how can i avoid this? sorry here's the sample code: ? if(!$submit){ ? form ? $filename=my.html; $fd=fopen($filename,r+) or die(Can't open file $filename); $message = fread($fd, filesize($filename)); fclose($fd); ? textarea name=message cols=95 rows=20? echo $message;?/textarea input type=submit name=submit value=modify /form ? }else{ $filename=my.html; $fd=fopen($filename,w) or die(Can't open file $filename); $fstring=$message; $fout = fwrite($fd, $fstring); fclose($fd); } ? the html file upon modify multiplies all the backslashes. any idea why? thanks in advance. - Original Message - From: Jason Sheets [EMAIL PROTECTED] To: Michael P. Carel [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, February 27, 2003 12:04 PM Subject: Re: [PHP] problem in writing into an html text file Hello Mike, You will need to better describe your problem and preferably show some source code. What characters are being added to it? You could use str_replace or the regular expression replacement functions but you should not get added characters in general. Jason On Wed, 2003-02-26 at 19:07, Michael P. Carel wrote: hi to all, Im having a problem writing an HTML code in a text file which comes from the html text area as an editor. There's an added characters inserted to it. How could i write to it perfectly? mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] One more string question
Trying using stripslashes() on the string variable prior to displaying it. That *might* not work for you, but I'd try that first. ---Matt -Original Message- From: Gregory Chagnon [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 11:12 PM To: [EMAIL PROTECTED] Subject: [PHP] One more string question When I submit a form with a text area containing the test //server/share and try to echo the variable it echos server//share. Is there any way to prevent the extra /'s? Thanks! -Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] text file reading and overwrite
I can't tell you anything about your problem without knowing what's going on (error messages are helpful). As for overwriting a file, just use: fopen($filename,w); The w option tells it to open the file for writing and to truncate it to zero-length. ---Matt, XPODesigns.com -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED] Sent: Monday, February 24, 2003 7:04 PM To: [EMAIL PROTECTED] Subject: [PHP] text file reading and overwrite Hi, Have a problem in reading a text file and displaying it in a text box area,also what function should i used to overwrite an existing text file. mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] having php auto load a page
Look up the header() function in the docs. Basically, you would do this: if($logged_in_ok) header(Location: .$url_to_go_to); There are some things to note when using header, so again, check the docs before you use it. ---Matt, XPODesigns.com -Original Message- From: Antoine [mailto:[EMAIL PROTECTED] Sent: Monday, February 24, 2003 11:18 PM To: [EMAIL PROTECTED] Subject: [PHP] having php auto load a page this might appear to be a simple question but I would like to know how I am able to have php auto load a different page. Here is the problem. I have a nice script that is used for logining in a user. But I have the script call itself so that it can test to see if the user name is correct. If the script is correct, I would like the page to just load in the user's main page. Is there any function that can do this? -- Antoine [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with Multiple Checkboxes
Yup, id is a valid attribute for virtually every HTML tag. I can't remember for sure which W3C specification that was in, but you can refer to most elements through JavaScript by using their ID's in both IE and Netscape 6+. ---Matt -Original Message- From: John Taylor-Johnston [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 2:42 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Help with Multiple Checkboxes input name=add type=checkbox id=add[] value=179 Does id even exist? HTH -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Another Logging Question
I'd like for my counter/logger to be fairly scalable, so I'm toying with two possible implementation routes: 1. Have the counter dump visitor info to a text file, then run a cron job on that nightly to process the data and perform a full analysis. 2. Have the counter dump the visitor info into a DB (probably MySQL), then process the data whenever the administrator wants to view his stats. Anyone have any suggestions or considerations on which method would work better? Is there something else I should do instead? Thanks for any input, ---Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Another Logging Question
Right now, it's logging the client's IP, the page that they're viewing, the page that they came from, the time of the visit, and their system and browser info. I think I'm going to go with a database to store the information, but do a mixture of long term and short term storage. I think I'll add an admin command that causes it to go through and generate statistics from the unprocessed data that's been collected, then move that data to a flat, compressed file for archiving purposes and just store the summary information. Ideally, processing of the raw data would only be performed as needed (and infrequently), so the majority of the database interaction would be inserts. Wow, that was a mouth full. I'd like to have the counter on each page of my site, and (hopefully) it will be getting quite a few hits. I still think the database will probably be the best way to go though as it keeps me from having to even think about file locking issues. ---Matt -Original Message- From: Justin French [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 5:12 PM To: Matt Honeycutt; Php-General Subject: Re: [PHP] Another Logging Question on 24/02/03 3:30 AM, Matt Honeycutt ([EMAIL PROTECTED]) wrote: I'd like for my counter/logger to be fairly scalable, so I'm toying with two possible implementation routes: what are you logging (what kind of data) 1. Have the counter dump visitor info to a text file, then run a cron job on that nightly to process the data and perform a full analysis. Archiving a report, rather than archiving the raw data can save lots of space, and yes a cron would be the best way. the downside is that the report is the ONLY record of the data. 2. Have the counter dump the visitor info into a DB (probably MySQL), then process the data whenever the administrator wants to view his stats. On-demand stats will use up more space long-term than generating monthly reports or something... but there are obvious benefits. The biggest issue IMHO is that if your site is processing a large amount of data, processing it over and over and over on demand is going to burden the server. Anyone have any suggestions or considerations on which method would work better? Is there something else I should do instead? If you're going to be dealing with large amounts of data, a combination. Perhaps perform a monthly analysis and consolidation of data to keep on demand / real time processing to the current month only... However, make sure you keep the long-term data SOMEWHERE, in case you want to change the reporting, method, or analyse the data a different way. If we're only talking about a counter on a few pages, real-time should be fine. Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Another Logging Question
Yeah, I know, but I'd like this counter to provide that functionality for those that don't have access to Apache's logging capabilities (either because their hosts don't allow it or because of the platform they're being hosted on). At some point, I'd like to provide a toggle to have the counter grab statistics directly from Apache's logs, but that's going to be much later on after I finish up some other projects. ---Matt -Original Message- From: David Freeman [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 5:44 PM To: 'Php-General' Subject: RE: [PHP] Another Logging Question Right now, it's logging the client's IP, the page that they're viewing, the page that they came from, the time of the visit, and their system and browser info. Ummm, you do understand that, for Apache at least, all of this information can be made available through it's logging? You also understand that by doing it through php you are, in effect, duplicating information that you can already access? Just checking... Seems a waste to me, that's all... Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] server hostname
This information is quite easy to find in the PHP docs. You are looking for $_SERVER['SERVER_NAME'], which is a predefined variable. ---Matt -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 8:24 PM To: [EMAIL PROTECTED] Subject: [PHP] server hostname hi to all; what function should i used to know the hostname of the server im using where php and apache reside? mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Displaying images
Robert, The image functions do indeed work, check the PHP docs for more info: http://www.php.net/manual/en/ref.image.php However, your server must have the GD libraries installed and PHP must be properly configured. The docs should be a good starting point if nothing else. ---Matt -Original Message- From: Robert Stermer-Cox [mailto:[EMAIL PROTECTED] Sent: Saturday, February 22, 2003 11:20 AM To: [EMAIL PROTECTED] Subject: [PHP] Displaying images Greetings, All, I'm a newbe to php and am trying to develop a routine to display artwork on my wife's site. I want to load from a flat file information about the artwork and image file names of the pieces. Then using the image file name, I want to display the image to the browser. I've figured out how to load the data from the file, but I could only find (PHP and MySQL Web Development, Welling Thomson) two functions to display the images: ImageCreateFromxxx or Imagexxx. Neither one works. In fact, Dreamweaver MX doesn't even show them as valid php functions. Any suggestions would be greatly appreciated Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Logging Referer
Hi all, I'm working on adding some logging functionality to a PHP image counter script that I wrote. The counter outputs an image representing the current number of hits and is used via an img tag. After it displays the image, the counter collects information about the user (browser version and OS, date and time of visit, ip, etc). I'd also like for it to log the referer, but because the counter is triggered via an img tag, the referer is always the page that has the img tag. Is there any other way to grab the referer that actually sent the user to the page that contains the counter? I'd like for the counter to work even when included in static HTML pages, so the including page cannot use any PHP to help facilitate this logging functionality. I hope all that makes sense. Anyone have any suggestions on how to achieve what I'm after? ---Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logging Referer
Yeah, I had thought about using JavaScript. I had hoped that there was another way, but if there is, I can't figure it out. ---Matt -Original Message- From: Justin French [mailto:[EMAIL PROTECTED] Sent: Friday, February 21, 2003 8:37 PM To: Matt Honeycutt; Php-General Subject: Re: [PHP] Logging Referer on 22/02/03 10:19 AM, Matt Honeycutt ([EMAIL PROTECTED]) wrote: I'd also like for it to log the referer, but because the counter is triggered via an img tag, the referer is always the page that has the img tag. Is there any other way to grab the referer that actually sent the user to the page that contains the counter? I'd like for the counter to work even when included in static HTML pages, so the including page cannot use any PHP to help facilitate this logging functionality. No, not easily :) On PHP pages, you could get the referrer, and append it to the URL, forcing the correct REFERRER through to the img script: img src=makeMyCounter.php?ref=?=$_SERVER['HTTP_REFERRER']? And you *could* choose to force .html files through the PHP parser, so foo.html could use the above code. I think the other alternative is to use javascript to build the img tag, because I'm pretty sure JS can figure out the referrer. But this has the obvious downside of JS being NO WHERE NEAR guaranteed to be on each browser. I think i'm missing something though, because I *think* those free counter/stat programs DO log a referrer... wait -- just checked thecounter.com, and they DO use JS for the referrer. Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: including in shtml
If you figure out how to do this successfully, please share. I'm forced to use SHTML for my error pages (404.shtml and whatnot), but I'd like to get those to interact with PHP as well. ---Matt -Original Message- From: Hans Prins [mailto:[EMAIL PROTECTED] Sent: Friday, February 21, 2003 8:30 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: including in shtml Im trying to write a poll script that is easy to intergrate into other documents of a site and thought that since shtml is a much used method, I want to make it available. Hans Prins [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] Hello, I have a problem with including a test.php into a test.shtml and passing a variable to the test.shtml which should be processed in the test.php the test.php document includes the following: --- ?php if ($HTTP_GET_VARS['theValue']) { print $HTTP_GET_VARS['theValue']; } else { print form method=\GET\ action=\test.shtml\ input type=\text\ name=\theValue\ size=\20\ input type=\submit\ value=\Submit\ name=\submit_button\ /form ; } ? the test.shtml document includes the following: - html head titlepoll/title /head body !--#include virtual=test.php -- /body /html I've also tried using the POST method but I got an error stating that post is not a valid method in shtml. I have also considered a session variable but since a session needs to initiated or continued before anything is output to the browser that wont work (I think). does anyone have a solution to get this to work? thanks, Hans -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: including in shtml
I'll check, but I'm pretty sure my host only allows me to edit the existing *.shtml files to customize my error pages. I don't think it will allow me to set the error pages to different URL's. ---Matt -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Friday, February 21, 2003 11:45 PM To: 'Matt Honeycutt'; [EMAIL PROTECTED] Subject: RE: [PHP] Re: including in shtml If you figure out how to do this successfully, please share. I'm forced to use SHTML for my error pages (404.shtml and whatnot), but I'd like to get those to interact with PHP as well. Most any web server will allow you to set a URL as the error handler, so you can have it as a PHP page. Is there a specific reason why you can't? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php