[PHP] Re: PHP Auto-Responder
On Mon, 16 Dec 2002, Kevin Stone wrote: > Yes that was the obvious solution unfortunately my web host does not have > crontab installed for users forcing me to seek other solutions. I have > asked my web host if they can install crontab and hopefully they respond > favorably to my request. If not then I may have a find a host just to do > this one job which seems like kind of a waste considering we're talking > about an infantesimal amount of bandwidth (four or five requests per hour). If lack of cron is the only thing holding you back, there's probably ways around that. You can make your PHP script available via the web, and then set up a home machine to request it every hour (assuming an 'always on' connection to the net). If you have a dialup, script your machine to dialup and request the page whenever you need to. Windows has the Task Scheduler, Mac (non-osx) has applescript (I think), and OSX and Linux have, well, everything. Otherwise, you could try an online cron service. Like: http://www.cronservice.com/ I have no idea how reliable they are, etc..., but it's likely cheaper than hosting with a new place. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Defaults in drop down list...
> I have a drop down list with all fifty states. very common. I conjured > up a way to store the value when you return to edit the form, but there > most be an easier way either in html, or in php. Here is what I > currently have. > > > Alabama > Alaska > Arizona > . > > > $stateselected['$state'] is an array that stores the state that was > selected on the prior form. is there an easier way, to have a default > state picked out of this drop down list.??? A trick I picked up from someone on this list: Alabama Alaska Arizona END; ?> That's it! If $state is set to 'AZ', then the $$state line creates a variable called $AZ, and sets its value to ' selected="true"'. Running the code produces this HTML: Alabama Alaska Arizona This solution might be considered ugly for several reasons: * all sorts of warnings are thrown, one for each unset state variable * it's entirely un-obvious to the casual code-reviewer what's going on. So it requires more documentation. * you run the risk of stepping on pre-existing variables. However, the upside, namely, eliminating a *ton* of code, is attractive enough to me that I use this for most select boxes I do. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Fw: HTTP_REFERER work without a problem....
On Wed, 15 Jan 2003, Kevin Stone wrote: > Chris I appreciate your response but please read my post again. I did not > suggest using the IP for user identification. I suggested using it as a > temporary id. I went on further to suggest to use sessions to identify > individual users behind a proxy server. But he also mentioned a round-robin proxy messing things up. I've had personal experience with IP addresses from AOL clients changing with each new connection. If your AOL users click through your site a few times, it's possible that their IP address will change between those clicks, thus making even a temporary id based on the IP address unreliable, and perhaps frustrating if your site keeps 'forgetting' things about the user. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: slideshow/flush
Hi, > I'm looking for a way to do something, not sure if someone can help me. > > I would like to be able to "control", in a way, what a remote user is > seeing, almost like running a slideshow. > > For example, user goes to website, it shows block of text or picture. I > login to admin area.I click "next" or something, and it either advances to > another page, or to another picture, and so on. > > I know you can kind of do a live output using flush, but what about > forcing it to another page? I don't think there's a way that you could force your server to push a new page onto an end-user's browser. However, you could replicate the behavior in a potentially annoying way: * serve up a page that has a meta-refresh of like, 5 or 10 seconds * that page includes an image, like "foo.jpg" * in your admin area, when you click "next", it does something to 'foo.jpg' (symlinks it to a new file, replaces the file, makes foo.jpg pull different stuff from a database, whatever) * next time the browser reloads due to the meta refresh, they see the new picture. It's not perfect, and there may be some cache issues that come into play. So you could tie your admin area to session ids, and have the reloading page have a dynamically determined image name. This might sidestep caching issues. Of course, there won't be immediate feedback to the user. They will have to wait a maximum of 5 seconds (or whatever) before they see your new image. The point is that you can't talk directly to the browser. You have to talk to the server, and then have the client periodically poll the server to see what new data it should get. I think. -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Bug?
On Fri, Jun 06, 2003 at 10:19:10AM -0700, Steven Walker wrote: > I get it... so instead I should use: > > include("/usr/home/sites/www.walkereffects.com/web/test/include.php") I would recommend using your .htaccess file, or ini_set, or something else to set your include_path variable to contain '/usr/home/sites/www.walkereffects.com/' or something like that. Your include() call can then just look like: and it'll work from anywhere, regardless of where the file that's doing the including is located [1]. As a bonus, if you ever change hosts, or your host re-organizes its directory structure, and all of your includes rely on the include_path, simply re-set include_path, and your site works again. joel [1] Of course, the order of directories in your include_path matters, too. If it contains '.:/usr/home/sites/www.walkereffects.com/', then a file matching in the current working directory will take precedence over the one in your site root. So keep that in mind... -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Web Based File Management and Security
On Mon, Jun 30, 2003 at 03:29:39PM -0500, Dean E. Weimer wrote: > It looks like there is no simple solution to this, and your point about > uploading a large quantity of files is well taken. > > I think as a solution I will enable a tsl/ssl ftp server and in the short > term use a published PHP solution notftp (http://wonko.com/notftp/) for > the one other user I currently have on the system, I will try to find a > solution for the problems with it under https. In the long term I will > probably write my own scripts that integrate into a database to do > directory caching, and is entirely based on forms using the post method, > and may eventually publish the scripts. > > Thanks to all those who gave me some added insight on this issue. One solution (this may have already been mentioned on this thread; I haven't read it all) would be to let users upload a .zip (or .tar.gz) file over HTTP, and have your server uncompress it and (optionally) create a directory structure matching the contents of that .zip. The 'gallery' image gallery software does .zip file uploading, and it's quite handy. Just a thought, joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Comma question
Richard, > This Programmer has actually read the Documentation and believed the > warnings that some day just plain old $strName might not be enough. Where might these warnings be? I just perused this URL: http://www.php.net/manual/en/language.types.string.php especially where it talks about the {} syntax, but I see no such warnings of future deprecation. I also followed a provided link here: http://www.zend.com/zend/tut/using-strings.php but that also doesn't mention this warning. Is this in fact syntax that will no longer work in some future version? If so, I'll start using {} everywhere I embed variables in strings, but I was unaware that stuff like this: "This is a $variable embedded in a string" might no longer work. If you have URLs, I'd love to read up on this. Thanks! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Pine config
[ straying even more off-topic... ] > It's doing this as a favor to you. If it displayed the "From" you'd know > less about the message than you know this way. I replied to Michael off-list, but since this popped up again... Pine uses a value called 'index-format' (configurable in the main config screen) to determine how and what to display for your email. Each piece of information (date, subject, author, etc...) that shows up in your index is represented by a 'token'. Pine has a stock set of tokens that it uses, but you can change the format to appear however you want. The default token is 'FROMORTO', which displays the 'from' address, unless 'From' is one of your own addresses (defined in pine's "alt-addresses" list); then it displays the 'To' value. To change this, simply define your own index-format, and use the 'FROM' token instead of 'FROMORTO'. More info is available by going to Pine's config screen (m, s, c), searching for 'index-format' (w index-format ), and hitting CTRL-G to bring up the help. HTH! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Sendmail "return-path" from my virtual webhost
> Emails sent from my php scripts, using sendmail, all have a goofy > "return-path" variable in the header. > > Is there a way I can correct this, or does it require a change to the > sendmail config file that I can't get to? You should be able to use the fifth parameter ("additional parameters") that was added in PHP 4.0.5 to properly set the envelope-sender, which will cause the 'Return-Path' header to be set properly. Quick example: '; $from = '[EMAIL PROTECTED]'; $subject = 'hey!'; $message = 'This is the message.'; mail($to, $subject, $message, "From: $from", "-f$from"); ?> Note that this doesn't do error checking on the status of the mail() command -- it's just a quick example. There also may be sendmail config things that prevent you from setting the Return-Path in this manner; that's out of my area of expertise, so if the above doesn't work, I'm not much more help... Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Auto Increment Problems....
[straying OT, but...] > Instead of incrementing to find the next row to count them, you dont have to > set the ID if it is auto increment. MySQL will do it for you (and i think it > might fill the holes too). Also, to get the num. of rows just do this - > > $get_rows = mysql_query("SELECT * FROM `table`"); > $num_rows = mysql_num_rows($get_rows); Oh my, don't do that! If you only want to get the number of rows in a table, don't bog down the MySQL server by doing a 'SELECT *' on it. This could be a *ton* of data... Why not use MySQL's built-in counting functionality: $result = mysql_query('SELECT count(*) AS count FROM table'); $count_arr = mysql_fetch_assoc($result); $count = $count_arr['count']; MySQL will be able to simply count rows a lot faster than actually SELECTing all of the data. Of course, if you're counting rows just to find out what the next value for an ID is, then, as you already said, you're doing the wrong thing. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: stripping quotes from urls and images
> hi guys i now have a problem with urls i need to remove the quotes from both > href="" and src="" > > so > needs to be and i cant > remove quotes from all string matches :| Someone mentioned this already, but you should really know that if you remove quotes from your HTML attributes, your HTML will no longer be forward-compatible with XHTML, which you really should strive for. What reason would you have for removing the quotes? There must be a better workaround than removing them. Regarding your question, it really depends on how you can operate on your HTML. Where is your HTML? Is it in a database, string, etc? Is it all in one chunk? That is, do you have stuff like this: This link has "quotes" that can't just have all quotes removed entirely from it? If you really need to remove quotes from attributes (and I don't think you do), and all of your HTML is in one big string, you're looking at a regular expression. Read up on them here: http://www.php.net/manual/en/pcre.pattern.syntax.php Yep, that's a lot of reading. But you should learn about regular expressions; they'll be useful all over the place. If you happen to be on a Linux/Unix/BSD/whatever machine that has man pages and perl installed, check out `man perlre`. Or read on-line here: http://www.perldoc.com/perl5.6.1/pod/perlre.html Some things to watch out for -- even if you do want to remove quotes from your attributes, I'm 100% sure you don't want to remove from *all* of them. Like this: Removing the quotes from the title attribute will likely break at least some browsers, if not all. So your regular expression needs to be able to handle that gracefully. Good luck! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: filter files in a directory
> I am showing a directory of files and I don't what all the files to > show on the screen. I was able to get the . and the .. not to show > with what I have below but there are some other files in there that look > like this mylist.confg. I don't want them to show in the directory > list. I tried && $files != "*.config" but this did not work . > Anybody have an suggestions on how to do this . I have look through > the manual and the mailing list but can't figure out how to make the > pattern to keep this from showing > > if ($handle = opendir('/path/to/list/directory')) { > while (false !== ($files = readdir($handle))) { > if ($files != "." && $files != "..") { > echo $files; > } != doesn't understand the glob (*) character, so the easiest way to make your example work is to use a regular expression match. Something like: if ($files != "." && $files != ".." && !preg_match("/\.config$/", $files)) { should do the trick. However, if you anticipate adding any more filters on the listing (.cfg, .txt, .conf, etc...) you might want to come up with a more general way to add filters besides simply tacking on stuff with &&. One thought might be to keep an array of patterns, and do a match on the whole array. When a new file needs to be filtered, simply add an entry to the array, keeping your code more-or-less clean. It's up to you, though. -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: hidden PATH_INFO
> Hi there. I'm trying to come up with a way to do > PATH_INFO urls without having to call a script. Let me > explain. > > I know how to make it work with a url like this: > > http://foo.com/bar.php/arg1/arg2/etc > > or even: > > http://foo.com/bar/arg1/arg2/etc > > What I'm trying to figure out is how to make it call > index.php without specifying it, like this: > > http://foo.com/arg1/arg2/etc > > Any pointers? This is something that will need to be done on the Apache level with rewrites, I believe. The PATH_INFO hack is a useful one, but if you don't want to call a script directly, I think you'll need a rewrite. There also may be another way to do it in Apache, but I don't think there's anything in PHP you can do to accomplish this. -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Sessions are acting strangely
> Hi there, > Im looking for ANY help regarding his problem - I find this interesting to > say the least. > > I recently switched to a new hosting company - they are running php 4.1.2 - > register globals is ON. > the sessions automatically expire without closing the window. if you load > index.php and wait past 30 seconds - the session variables are empty - > Sometimes - although not reliably - if you wait another 30 seconds - the > variables are back? - this is very strange? - here are the files I have > setup to illustrate this problem. > Im using the default php-ini file - so no weird session expires or garbage > collections stuff. Do you know if your hosting company has a multi-webserver setup? If so, do they have a shared /tmp directory (where PHP stores session information), or is it unique to each server? If your hosting company has many different webservers, each reload might hit a different one, and each may or may not have your session information in its /tmp directory. A solution is to write your own session handlers, using a database, the shared portion of the filesystem, or some other method of preserving the data. Otherwise, have you checked with your hosting company to see if this is a common issue that their customers have? -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: counting clicks on a flash ad
On Tue, 29 Oct 2002, Ben-Nes Yonatan wrote: > does anyone know a way to count those clicks? > or just got a link to a site which explain alittle? You might try using software like phpAdsNew: http://www.phpadsnew.com/ It has a fantastic admin interface for you and for the advertiser, it supports Flash banners, as well as everything else you want to throw at it, it's free, and it's free. Installation is remarkably easy. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Does anyone know if this is possible?
Hi Raymond, > I have made a website with a webshop and the orders are written down in > txtfiles and a faxserver is scanning a directory for txtfiles and sends them > as faxes. > > So I am trying to write the txtfile like I should have written the order in > a table. Or you can say I am trying to make some columns in the txtfile. > > Something like this: > > 1pizzacheese, beef, tomato,5,- > ham, bacon etc > 2burgerscheese, bacon2,- I *think* if you're committed to doing this in PHP, you'll need to look at the sprintf() or printf() functions: http://www.php.net/manual/en/function.sprintf.php You're given some level of control over the output of your program. I don't know if you can get what you describe above, though. If you're not adverse to looking to another language, Perl was built to do exactly this. Perl Formats do what you need -- they provide a method for generating "simple, formatted reports and charts", according to the camel book. I know of no analagous capability of PHP (although I may very well be wrong). If you can't use perl for the whole thing, perhaps you could have PHP do all your logic, and then pass the data to a perl script to format and save it to a file. Or maybe sprintf() does everything you need... Joel (more on perl formats: http://www.perl.com/doc/manual/html/pod/perlform.html) -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Why $ on variable names?
> That's the way the language designers did it, and there's LOTS of > PRODUCTION code out > there that uses it. > > See also the precedence of PERL. Well, perl and PHP use the $ for slightly different reasons, it seems. In perl, the *thing* in front of a variable name ($, @, %) indicates what context the variable is being used in (scalar, list, hash). Depending on what you want your variable to do, using a different character makes all the difference. The leading character is not a part of the variable name. PHP seems to use the $ more for readability, and possibly for making the language easier to parse (and, of course, the aforementioned string-embedding). Since all variable types (scalars, arrays, objects) seem to use the $, it seems more for syntactic uses and less as something that changes how the object behaves. However, I like having it there. It (as someone else mentioned) helps me quickly see where variables are used, both in and out of strings. It also probably helps syntax-highlighting text editors read the code more quickly, although it may be just as easy without. All I know is when I think back to programming C++, I can't imagine how I could deal with variables that didn't have something in front of them to separate them from barewords. Oh well. -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Searching
> i have an array like: > > Array > ( > [1] => Array > ( > [alias] => foo > ... > ) > [2] => Array > ( > [alias] => bar > ... > ) > ... > ) > > I need some way to find out, if an alias "foo" is in the array. Any idea how > to do this? Assuming your outer array is called $array_of_arrays: Or, you can look at this: http://www.php.net/manual/en/function.in-array.php if you're not sure what key 'foo' will be at, or this: http://www.php.net/manual/en/function.array-search.php if you're not sure what key 'foo' will be at and you want to know what that key is. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Exporting mySQL Table Data to .csv
Hello, > I use phpMyAdmin which enables me to take dump of > mySQL Table Data into Comma Seperated Values file > (.csv) > > Now, i have to create such a program that accomplishes > this, without using phpMyAdmin. Can someone guide me > to this procedure.. This isn't a PHP script (it's Perl), but it does exactly what you want: http://oss.gospelcom.net/staff.php The first tool listed there is called 'cvsdump' -- it dumps, processes, and mails a MySQL table in CVS. HTH! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: banner rotation and advertisement
> Try phpadsnews. phpAdsNew can be found on SourceForge here: http://sourceforge.net/projects/phpadsnew/ I've been using it in production for over a year now, and have found it to be quite a handy program. -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Adding X days to a time string...
On Fri, Nov 21, 2003 at 11:15:20AM -0500, Jeff Lewis wrote: > Sorry, I may have muddled that...the issue isn't converting a string to > a time, it's taking a time (102636 for example) and adding 30 days > to that. Ah, but it is an issue of converting a string to a time. strtotime() can "Parse about any English textual datetime description into a UNIX timestamp". It also has a handy optional parameter telling you when to consider "now". So to add thirty days to "now" (102636 in your example): Such a handy function -- no need to worry about leap years, number of days in a month, etc... -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping problem?
On Wed, Jan 07, 2004 at 09:17:35AM +1100, Martin Towell wrote: > This is probably more like what you need. > I can't see why you'd need to loop through your results using two different > methods (while and for) > > require 'database.php'; > $t_02 = "subnets"; > $sql_subs = mysql_query("SELECT * FROM $t_02",$db) or die(mysql_error()); > $num = mysql_num_rows($sql_subs); > for ($z = 0; $z < $num; $z++) > { > list($id, $sub, $msk, $dns01, $dns02, $rtrs, $rnge) = > mysql_fetch_array($sql_subs); > $vlans[] = "subnet $subnetmask $msk {option domain-name-servers > $dns01, $dns02;option routers $rtrs;range $rnge;}"; > } > // Write everything out formated... > for ($z = 0; $z < $num; $z++) > echo "$vlans[$z]\n"; No need to calculate the number of rows: netmask $msk {option domain-name-servers $dns01, $dns02;option routers $rtrs;range $rnge;}"; print $tmp; $vlans[] = $tmp; } ?> I would recommend not simply doing a select *, but rather specifying which columns you want. That way, if your database schema changes (e.g., you add two more columns), your code won't break. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping problem?
On Tue, Jan 06, 2004 at 05:33:41PM -0500, joel boonstra wrote: > I would recommend not simply doing a select *, but rather specifying > which columns you want. That way, if your database schema changes > (e.g., you add two more columns), your code won't break. And, responding to myself, specifying your columns is also good practice because MySQL makes no guarantees about the order that columns are returned when you say "SELECT *". Today, it may well be the order that you specified when you created your table. With the next upgrade, it may be alphabetical order, or by column type, or some other order that the software chooses. If you specify column names in your SELECT statement, you don't need to worry about it. This is especially important when you are using list() to assign variables based on their position in your fetched array. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] odd and even numbers
On Fri, Jan 16, 2004 at 02:30:59PM -0600, Jeremy wrote: > function isOdd ($value) { > return (int)$value % 2 ? true : false; > } > > Returns true/false if the value is odd. Also rounds down floating point numbers > given as the test value. No need to explicitly state "true" and "false". Just negate the result of your modulus operator, and take advantage of the fact that "0" is false, and "1" is true: function isOdd ($value) { return !((int)$value % 2); } -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] odd and even numbers
Jake, > This worked.. somewhat.. here is what I want to do though. > > I have two people checking the same email address. I want to break up the > emails 50/50 to each person. What values can I put into the random number > generator so that I can get closer to 50/50. I just set up a test page with: > > $rand = rand(1, 501); > > echo $rand; > > if ($rand % 2 == 0) > echo "even"; > else > echo "odd"; > > > and I'm getting a lot more evens than odds, so the one person would get more > emails than the other. Is there any substitution to rand that I could use to > get one message to go to one person, then the next to the other? I'd like it > to be as close to 50/50 as possible. Is there any way you can save state? That is, can you keep track of who got the last one, and use that to determine who should get the next one? Otherwise, why not just rand() between 1 and 2? rand(1,2) will, on average, give you as many 1s as 2s (like flipping a coin). There will likely be runs of 1 or 2, but over time, doing rand() with two possible values versus rand() with 501 values will not be significantly different. In fact, since there is one more odd than even between 1 and 501 (inclusive), you will be getting slightly more odds than evens with that range than you will with a range of 1 and 2. Also, which PHP version are you using? If before 4.2.0, you should seed the random number generator with srand(). If you are using 4.2.0 or greater, and still seeing non-random behavior, I don't really have an answer. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with preg_replace
On Mon, Jan 19, 2004 at 06:50:37PM +0200, John Clegg wrote: > Hi > > I am having some problems with preg_replace and I wondering if someone > could suggest a fix or explain why it is not working. > > > > Here is the Code: > * > $code = "blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah"; > $url = "'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]'"; > echo "BEFORE : $code"; > $replace = "Foo"; > $code = preg_replace($url,$replace,$code,1); > echo "AFTER: $code"; > ?> > ** > > Here is the results of the script: > > ** > BEFORE : blah > http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah > > AFTER: blah > http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah > > ** > > It should give the following result: > > ** > > AFTER: blah Foo blah > > ** preg_replace expects the first argument to be a pattern, which should be enclosed in forward slashes ("//"). So your $url variable should be surrounded with slashes. You have single quotes in your $url variable, but I don't think that PHP behaves like perl in letting you use whichever delimiter you choose. Try replacing the single quotes with forward slashes. Additionally, if you're only doing a simple string substitution, you should use str_replace instead: http://php.net/str_replace You won't need the "/" delimiters, and it will be faster than using preg_replace. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP with Style Sheets
On Mon, Jan 19, 2004 at 11:08:29AM -0600, John Nichel wrote: > Freedomware wrote: > >OK, it looks like there are at least three ways to do this. I now have > >an original style sheet with a .css extension and copies with .php and > >.css.php extensions. > > > >All three style sheets have the following code at the top: > > > > >header("Content-Type: text/css"); > >?> > > I would think that the above is going to cause problems. First, if you > have something like this... > > > > My Page > > > > > and style.php has the header call in it, you're going to get an error. > Second, I don't know how much differently the browsers handle text/html > and text/css, but being that the header has to be sent before any output > to the browser, you will have changed the mime type of the whole document. I'm guessing that the .css file will be used in the traditional way: > > > My Page > > Now, it's the browser that's fetching the .css file, so the header() call isn't a problem at all. The browser simply performs a separate request for that file, so its header() information is sent in response to that request. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with preg_replace
On Mon, Jan 19, 2004 at 07:15:53PM +0200, John Clegg wrote: > Hi Joel, > > Thanks for the reply. > > I have tried using "/" to delimit the string and I get the following error > > String > > $url = "/http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]/";; > > Gives the error: > *Warning*: Unknown modifier '/' in* /test.php* on line *8* > > I found out that I could use ' to delimit from Example 5 in the php > manual page for preg_replace. Whoops, you're totally right. The single quote should work fine. I shouldn't underestimate PHP ;) > Also I need to replace only one occurance of the string at a time, so I > can't use str_replace :-( . > > Any other suggestions?? The problem is that there are still special chars that need escaping. Specifically, the question mark (?) and the square braces ([]). Here is some modified code (apologies for poor word-wrapping): http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah "; $url = "'http://www.foo.com/maxbid/Unsubscribe.php\?EmailAddress=\[MAIL\]'"; echo "BEFORE : $code\n\n"; $replace = "Foo"; $code = preg_replace($url,$replace,$code,1); echo "AFTER: $code\n"; ?> When I run this, the output is: BEFORE : blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah AFTER: blah Foo blah Next time, I'll test out my answers before I give 'em. HTH! -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] An array curiosity....
On Mon, Jan 26, 2004 at 08:50:51AM -0600, Jay Blanchard wrote: > Out of curiosity, and because I have never noted this in other > languages, why doesn't an 'open' comma at the end of an array throw any > kind of error? Is it because the comma denotes another element in the > array even if nothing is their? For example > > $arrBadInfo = array( > 'stuff ', > 'morstuff', > ); > > does not throw an error - even syntactical - This is as a convenience to programmers. Often arrays have things added or removed as you're coding -- not having to worry about removing a trailing comma for an element that is now the last one, or adding one to previous elements when adding items to the list is a small but useful timesaver. Perl does this as well. I'm not sure which other languages do, but I like it. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Chat REALTIME
> I need to build a php-chat (online support system), but in realtime. > I've develope a system that refresh in browser client in 5 seconds. But > i need a system that works in realtime, what i meen is when a client or > the server send a message, the browser refresh when a message was sent. > All this without JAVA. Have you thought about using a pre-built system: http://www.phplivesupport.com/web/phplive_web/ It does cost money (one-time fee, no recurring fee), but I would imagine that spending time to build one yourself would also cost money (in terms of time). I have never used it, but it definitely looks to be worthwhile. -- [ joel boonstra | [EMAIL PROTECTED] ] -- 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] function scope question
Hello, I wrote a PHP class to display an HTML calendar, and then wrote a subclass of it for a specific project I'm working on. Here is the entirety of the subclass: // create our new sub-class of the calendar class rantCal extends calendar { function get_link($day) { $link = ""; if (valid_date($this->my_year, $this->my_month, $day)) { if (rant_exists($this->my_year, $this->my_month, $day)) { $link = "index.php?date=$this->my_year-$this->my_month-$day"; } } return $link; } } Basically, it's used to determine if a given date should be linked or not. When I wrote it, I didn't expect it to work, since these two function: valid_date() rant_exists() are defined completely outside of the class. In fact, they're defined in a functions file that I include (with include()) above where I define my rantCal class. Shouldn't their names not be recognized within this class? I was assuming that a class was entirely self-contained, so it can't know about functions defined outside its scope. However, it works just fine (that is, the functions get called), which is helpful, but it doesn't seem like the way things should work. Am I completely wrong? I seem to recall that this sort of thing should work in a more strict OO language, like C++. I'm using PHP 4.0.6, if that's important. -- [ joel boonstra | [EMAIL PROTECTED] ] -- 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 call method from another class
> first create an instance of class B like this... > > $test = new classB(); > > Now, u can refer to any function or method of classB like this: > > $test->hello(); // where hello() is a method of classB.. That's not what the original question was, though. David (I think, unless I got my nested replies wrong), was looking to call a method of ClassA with an object of ClassB: > > If I have a PHP class (let's say it's called ClassA), how do I call a > > method from another class (ClassB) within ClassA? Thanks. The answer to this question, unless my OOP theory is gone, is that you can't, unless ClassB is an extension of classA. So if you have: class ClassA { // some vars function get_contents() { // some stuff return $something; } } and then: class ClassB extends ClassA { // some vars function display_contents() { print $this->get_contents(); } } Then you're good. Otherwise, I don't think it's possible... -- [ joel boonstra | [EMAIL PROTECTED] ] -- 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] prev next links
> Does anyone know of a well written example of this? I have seen so many > examples, but the over head just seems to be too much... does anyone have a > smooth and well written routine? > Regards, > Kunal Jhunjhunwala I think this may help out. I wrote a site that has a daily devotional on it, and contains links to previous and next days. Here's the code: http://yourdomain.com/?$prev_year-$prev_month-$prev_day; $next_link = "http://yourdomain.com/?$next_year-$next_month-$next_day; // display them print "yesterday"; print "tomorrow"; ?> This doesn't take into account whether or not yesterday or tomorrow's objects or files or whatever actually exists. Since that is site-specific, you'll need to add that sort of logic yourself. Hope that helps! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] prev next links
> // build your links > // this will, of course, change with your dating schema > $prev_link = "http://yourdomain.com/?$prev_year-$prev_month-$prev_day; > $next_link = "http://yourdomain.com/?$next_year-$next_month-$next_day; Sorry, I omitted the closing quote mark on these lines. Here is a non-syntax-error-ridden version: http://yourdomain.com/?$prev_year-$prev_month-$prev_day";; $next_link = "http://yourdomain.com/?$next_year-$next_month-$next_day";; ?> Sorry! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDF4PHP Class
> Hi there, > > someone have some experience with this class?? I've never used that one, but I just had a wondrous experience with: http://ros.co.nz/pdf/ I downloaded it, and got it running and working (as a non-privileged user in a SAFE_MODE environment) in about 15-20 minutes. No extra modules required, nothing to compile. Just unzip, and it works (more or less). The only potential sticky point is that it writes to /tmp when images are involved, so if that's a problem for whatever reason, you'll need to change one line. Otherwise, it works great! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: alphabetizing titles when first word begins with 'The','A',etc.
Steph, > Hi. Im using MySQL and as part of my tables I have titles (of stories). > My question os in regards to outputing those titles. Some of the titles > begin with words such as 'The', 'A', 'An', etc. Is there a way to order > these particular titles based on the second word in the title?? Late reply -- I don't check this folder that often. I had this exact problem. Don't bother with temp tables, or extra fields, or anything like that. You can build it all into your MySQL query. A resident MySQL expert gave me this recipe (well, one very similar): No fuss, no muss. You don't have to worry about what order they were inserted in, artificially munging your data, or anything else. HTH! -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] wordwrap not working
> it should print like this: > > The quick brown fox > jumped over the lazy dog. > > but it still printing like this: > > The quick brown fox jumped over the lazy dog. HTML treats bunches of whitespace as one space. Look at the source of the page; you'll see that it's doing what it should. If you want your HTML to appear wordwrapped, modify your PHP to use the 'nl2br()' function: This will convert all newlines to tags, and your HTML output will look just like your text output. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] wordwrap not working
> If your viewing the output through a browser, try this; > > $text = "The quick brown fox jumped over the lazy dog."; > $newtext = wordwrap( $text, 20, ""); > echo "$newtext\n"; > ?> Ah, this is a better solution than mine -- I didn't know wordwrap had the 3rd (and 4th) parameters till now. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache Server Side Includes mixed with PHP pages
> Thanks Martin - that does work. I was just thinking in ASP terms. But I > am curious as to whether Server Side Includes can work together with > php. Nope, at least not with Apache <= 2.0. Apache 2 will let you have multi-pass parsing, so your PHP could output SSI, which would then be parsed. Why you would want this, I don't know, since PHP is much more fully featured than SSI, and can do everything SSI can. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] why doesnt this work???
Hello, I read a ton of replies to this already, and there was a lot of good advice. However, it should be worth noting (and I don't think anyone did already) that you have a misspelling in this code: > $password = ""; > // . . . > $query = "select * from medlemmer where bruker = '$bruker' and passord = > '$passord'"; > // . . . > if( $line[1]='$bruker' and $line[2]='$passord') echo "hei $bruker."; You initialize the variable as $password, but refer to it as $passord (no 'w'). Maybe that was just a typo in the email, but that will definitely be a problem in the code, too. Of course, all the other advice ('==' instead of '=', '&&' instead of 'and', etc...) should be heeded as well... -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Images
> > > > > > > > > The code is like this: > > > > > > > > > $szPicture = "myimage.gif"; > > > > > > $url = "<A HREF="http://www.mysite.com/"">http://www.mysite.com/"</A>; . $szPicture; > > > header("Content-type: image/gif"); > > > header("Content-Length: " . strlen($url)); > > > echo $url; > > > You're properly printing out the Content-type header, but not the actual image data. You need to get the get the binary data (probably using a binary-safe read) from the image file you want to display (in $url), and then print that data out after the content-type header. Right now, a browser would get sent a content-type header for a gif, and then the following string: http://www.mysite.com/myimage.gif and that's not valid contents for a .gif file. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- 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 & ssi
> No, this isnt possible - but the constructs in PHP should allow you to > do anything you can do with SSI just as easily. This may be possible with Apache 2.0 and greater, once it's in stable release (perhaps it is already). It would allow the server to perform multiple passes on documents, thus allowing your PHP script to execute and output SSI, which would then get parsed by the server and be executed, again. Why you would need this, I don't know. As people already mentioned, SSI's very limited capabilities should all be available in PHP. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- 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] content management
On Mon, Jan 26, 2004 at 08:07:21PM -0300, Pupeno wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Does anybody know of an extremely simple CMS (to serve pages, documents, not > news based like most of them) that can store pages in various languages and > comes with interface in various languages (or that it is translatable) ? Straying a bit OT, since this is a PHP list, but MovableType: http://movabletype.org/ is a great CMS whose interface can be fully translated: http://www.movabletype.org/docs/mtmanual_multilanguage.html#multilanguage%20support into the language of your choice. I assume that it can store pages in various languages if you author them that way, but I have no direct experience doing so. To bring it back to PHP, MovableType can be made to output PHP pages if you so desire, letting you extend its functionality that way (or through its built-in plugin interface, which is Perl). joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 09:48:22PM +, Stuart wrote: > Eric Gorr wrote: > >A solution I found was in dirA/index.php, to chdir( ".." ); before > >the require_once, which moves the current directory to SiteRootDir and > >allows otherfuncs.php to be found ... is this the best way to solve this > >problem? > > Qualify relative paths by prepending $_SERVER['DOCUMENT_ROOT'].'/' - I > usually define a constant at the start of all scripts like so... > > define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'/'); Why not use php's include_path setting? No need to define constants, no need to worry about the location of your script relative to the document root, and it works with more functions than just include() and require(). I have found it to be the cleanest, most reliable, and most portable way to deal with file paths. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 04:35:14PM -0600, John Nichel wrote: > And if document root is different from include path? What if the > include path is outside of document root? You CANNOT rely on > include_path to accomplish this. Sorry, I should have been more specific. I was implying that you would set the include_path to include your document_root for your whole site, using httpd.conf, .htaccess, or ini_set() (.htaccess probably being the easiest). # httpd.conf or .htaccess: php_value include_path '/path/to/document/root:.' # ini_set(): ini_set('include_path', "{$_SERVER['DOCUMENT_ROOT']}:."); You could also modify the ini_set() method to append document_root to your current include_path setting, using the PHP_INCLUDE_PATH constant. I think. But you're right, you can't rely on the default include_path setting to contain anything useful. If you set it manually, though, it can contain whatever you want. Unless I'm misunderstanding what you're saying... joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website Architecture
On Thu, Feb 05, 2004 at 05:42:54PM -0500, joel boonstra wrote: > # ini_set(): > ini_set('include_path', "{$_SERVER['DOCUMENT_ROOT']}:."); Replying to myself, it appears that PHP >= 4.3.0 has a family of functions specifically for tweaking include_path: http://www.php.net/manual/en/function.set-include-path.php When using ini_set() or something similar to tweak the include_path, I would recommend using it in conjunction with a file that is auto-prepended to all of your .php scripts (assuming you want all of your scripts to use the same include_path): # in .htaccess php_value auto_prepend_file "path/to/init.php" # init.php set_include_path('/new/include/path'); You can of course put other stuff that needs to apply to all .php files in init.php, too. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can PHP redirects be detected?
On Mon, Feb 09, 2004 at 02:31:16PM -0500, Lowell Allen wrote: > A recent thread on the WebDesign-L raised the question of whether search > engines can detect (and penalize sites for) PHP redirects of the form: > > header("Location: http://www.whatever.com/";); > > I don't see how that could be the case, since the redirect occurs on the > server before any HTML is output to the browser. Someone else says: > > > No, the header() redirect immediately tells the /client/ to make a second > > GET request at a different location and the client (search bot) must > > actively make that 2nd request to the "Location:" URL (what happens if you > > request amazon.com) Note this is different from simply sniffing the UA > > string from a single request and serving altered content. This is accurate (the explanation from webdesign-l). Try it yourself: === $> telnet www.yourserver.com 80 Trying 123.456.789.000... Connected to www.yourserver.com. Escape character is '^]'. GET /path/to/redir.php http/1.0 host: www.yourserver.com HTTP/1.1 302 Found Date: Mon, 09 Feb 2004 19:49:35 GMT Server: GoGoGadgetWebserver/0.3 Location: http://www.example.com/ Connection: close Content-Type: text/html Connection closed by foreign host. === Assuming redir.php contains a header() call that sends "Location:", the bot will see something like that. It's up to them to parse that, determine the status code (302, in this case), and decide what to do with it. Browsers just do this transparently. > What say you, PHP list? Would it be better (in terms of search engine > detection) to use include() to serve different or altered content? Do neither. Create excellent content, structured well, and the search engines will reward you for this. Try to trick them, and they will likely figure it out and penalize you. However, if you're asking whether or not Google can determine if you're using include() to serve up different content based on the UserAgent or perhaps the IP address, then no, bots can't figure that out. Unless they switch useragents/IPs and compare the results that they get. Or unless a human complains that the listing is innacurate. etc... -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can PHP redirects be detected?
On Mon, Feb 09, 2004 at 02:48:07PM -0500, John W. Holmes wrote: > As for whether a redirect is penalized or not, I doubt it. It'd be in the > best interest of the search engine to follow the link just like it's going > to follow any link on a page and index the content. Now, whether the indexed > content will show up at domain.com in the search engine or > domain.com/redirected/url/page.php, I don't know. In my experience, it depends on the status code sent with the redirect. If it's a 302, then the original URL is indexed. If it's a 301 (Moved Permanently), then the redirected URL is indexed. I have nothing to back this up other than trying it out with some sites, and watching the results (with Google) over a few months, but it makes sense to me. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] weird header() (bug may be)
On Thu, Feb 12, 2004 at 05:20:29PM +1100, adwinwijaya wrote: > Hello php-generaler's , > > I have a script like this : > > if($foo == 'something'){ > header('Location:to_another_page.php') ; > }else > { >do another thing in here > } > > header('Location:to_previous_page.php'); > > > I got a problem ... when $foo == 'something' .. it wont redirect me > to to_another_page.php but if I put die(); after calling > header(); .. it will work ... The reason it works after you put die() after calling your first header() is because once you send the location header, you can't send other stuff. Using die() causes script execution to end, which lets the header work. So put something in there that causes script execution to end (e.g., exit()). The proper code (including the properly-formed URL mentioned by others) is something like: if($foo == 'something'){ header('Location: http://www.example.com/to_another_page.php') ; exit(); }else { do another thing in here } header('Location: http://www.example.com/to_previous_page.php'); exit(); // for good measure joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Browser Detection another page
On Fri, Feb 13, 2004 at 11:57:59AM +1100, PETCOL wrote: > Then I need to take the user to another page. > > > if (strstr($HTTP_USER_AGENT,'Windows CE')) { > //go to the Windows CE version of the site > } else { > // go to or Stay on the large version > } > > ?> Hopefully you're aware that $HTTP_USER_AGENT is an unreliable variable, in that it is sent by the client, and can contain virtually anything. I saw a response letting you know how to do this, but I would recommend not sending people to different pages based on which browser/OS they're using. The most I would use $HTTP_USER_AGENT for is if I'm presenting a list of different OSes (say, for links to OS-specific downloads), and I want to select an intelligent default. It should be possible to use CSS/(X)HTML to present your content in a way that is accessible to whichever browser accesses your site. IMHO, browser-sniffing to serve different content is a bad idea. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Browser Detection another page
me big sites that have decided that a CSS design is viable: http://msn.espn.go.com/ http://news.com.com/ http://www.sprintpcs.com/ I'm not an expert (unfortunately) on the specifics of how to acheive this sort of a design. I'd recommend checking out Jeffrey Zeldman's book "Designing With Web Standards" as a great overview on how to get started on standards-based design. One very brief example of the sorts of thing you could to do allow browsers to use your site would be to use the @import CSS directive to include your stylesheet. Newer browsers can handle this; older ones can't. So when I go to http://csszengarden.com/ in Mozilla, I get a nice site, because it understands @import. When I go there in Netscape 4.78, I get the HTML (which is usable), but not the design. For discussion: http://css-discuss.incutio.com/?page=ImportHack (and I hear that's a great email list for specific CSS-related topics) The key difference in serving designs in this manner is that you are not coding for browsers or platforms; you are coding for capabilities and standards. It's pretty clear that browser rendering/standards support is only getting better, and that the number/variety of browsers is growing. > Could you throw in another 2 cents? :o) I guess that was more like 10 cents. Feel free to continue this off-list if you want to discuss more. This really doesn't have much to do with PHP anymore ;) joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Sat, Feb 14, 2004 at 03:05:40AM +0800, Jason Wong wrote: > $doo[1] = ''; > $doo[2] = ""; > > foreach ($doo as $dah) { > if (preg_match('//i', $dah, $matches)) { > print_r($matches); > } > } Note that characters within square brackets don't need to have the | to separate them; it's a character class, so it will match any character within the brackets: if (preg_match('//i', $dah, $matches)) { Also, it's probably good to put a non-greedy modifier after the *s to prevent .* from matching too much. Compare: '; $doo[2] = ""; foreach ($doo as $dah) { if (preg_match('//i', $dah, $matches)) { print_r($matches); } # adding ? after the * if (preg_match('//ig', $dah, $matches)) { print_r($matches); } } ?> 'Course, it still doesn't match multiple images in one line. preg_match_all() could probably help out there. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Fri, Feb 13, 2004 at 02:19:11PM -0500, joel boonstra wrote: > if (preg_match('//ig', $dah, $matches)) { > print_r($matches); > } Doh! The '/ig' should just be '/i'. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Browser Detection another page
On Fri, Feb 13, 2004 at 08:01:00PM +, Stuart wrote: > [EMAIL PROTECTED] wrote: > >Before you read my comments below, let me say that I'm not trying to prove > >you *wrong* or even express disagreement with the points you made; I'm > >just interested in your reasons. > > An interesting topic, but the OP was checking if the client was a PDA. > Maybe it's just me, but I feel that serving a site that wasn't designed > for viewing on PDAs to PDAs is generally a bad thing. True, PDAs can't generally handle the same size/number of graphics that a desktop browser can. But what about the Treo? The Sidekick? The Zaurus? Do those get browser-detected as well? Or will they still get the same designed-for-desktop site that all non-WinCE devices get? As an alternative, use the same (X)HTML, and design an alternate stylesheet for handhelds, using the CSS media type options: http://www.w3.org/TR/REC-CSS2/media.html#media-types Now you can maintain the same content, and just have two different stylesheets. 'Course, this is the ideal; it's probably the case that not all handheld browsers recognize media="handheld" like they should. Perhaps the @import rule trick will work, as well. There is some discussion on alistapart: http://www.alistapart.com/articles/slashdot2/ about handheld emulators, and how XHTML/CSS-designed sites appear on them. However, this is way way OT now, and should probably be carried on offlist. Or, better yet, I bet css-discuss can provide tips for using CSS to support handheld browsers, without having to duplicate content or do browser sniffing. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: preg guru question
On Sat, Feb 14, 2004 at 12:50:55AM -0500, Adam Bregenzer wrote: > As far as I could tell the regexp I posted was the only one to use a > subpattern to match the first quote type used and then re-apply that > after matching the file name: > '//i' > > I am a bit of a regular expression fan and I would be interested in > seeing another way to match without using subpatterns. What was Joel's > regexp again? You're right that my regexp[0] didn't require the quote marks to match each other. Depending on how strict/lax you want to be, that might be a feature or a bug ;) As to doing it without subpatterns... this seems to get there: '##i' but isn't as elegant or extensible as yours, although it does allow for (that is, an empty src attribute). Also, it's less clear where your matches are in mine, since there are so many parens. IOW, Adam's is better ;) [0]: The one I posted was: '//i' which didn't require quotes to match each other, didn't allow for arbitrary whitespace, and didn't allow for XHTML-style tag closing. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] heavy parsing of text, storing both versions
On Fri, Feb 20, 2004 at 10:35:11AM +1100, Justin French wrote: > 1. Parse the text on demand into HTML -- the parsing script is to > heavy/slow for this. > > 2. Store both the plain (shorthand HTML) text and parsed XHTML versions > of each field -- the problem with this being that i'm storing double > the data in the database... combine this with versioning of each > 'page', and I'm going to be storing a LOT of data in the DB. > 3. write a reverse set of functions which converts the XHTML back to > the shorthand on demand for editing -- this seems great, but I don't > like the idea of maintaining two functions for such a beast. > > > Has anyone got any further ideas? 4. Store the plain (shorthand HTML) text and when users 'save' changes, generate a static page containing the transformed XHTML version. You will have the processing overhead once (when data is changed), and everytime else visitors get static files. It sounds like #3 would be quite difficult. Going from HTML->XHTML you know what the end result would look like. Going the other way, you won't know for sure what the users originally entered when they authored the content. I'm assuming this isn't a 1-to-1 transformation, so that these: Some bold text Some bold text Some bold text will all get turned into: Some bold text If you turn the text back into , then it's not clear which of the three options you should use. Unless I'm misunderstanding... joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] heavy parsing of text, storing both versions
On Thu, Feb 19, 2004 at 09:15:35PM -0500, John W. Holmes wrote: >>2. Store both the plain (shorthand HTML) text and parsed XHTML >>versions >>of each field -- the problem with this being that i'm storing double >>the data in the database... combine this with versioning of each >>'page', and I'm going to be storing a LOT of data in the DB. > >4. Store the plain (shorthand HTML) text and when users 'save' changes, > >generate a static page containing the transformed XHTML version. You > >will have the processing overhead once (when data is changed), and > >everytime else visitors get static files. > > Isn't that just an alternate version of #2? You're still duplicating the > data and taking up storage space. Again, I wouldn't really be worried > about this, but that's the issue presented in #2. Sure, static files > would probably be faster, but that doesn't answer the issue of when/how > to do the conversion. Version #2 involved an identical database structure, or multiple database fields, or some sort of redundant data storage that mirrors the HTML database structure. The bigger problem to me seemed to be the complexity introduced into the database, not the extra storage space required. This solves the script run problem (only runs once), and lets the database remain as originally planned. The point is that the XHTML version is only necessary for display on the finished webpage, and the simple HTML version is only necessary for editing in the administrative interface. Publishing static XHTML files eliminates the need to do database interactivity on each page request (after all, the content isn't going to change with each request, is it?) and keeping the HTML in the database lets the admin. interface be as interactive and dynamic as is necessary. Just my $.02, though -- I'm not going to have to end up maintaining this, so the best answer is the one that works the best for the OP. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: why use safe mode?
On Wed, Mar 03, 2004 at 08:39:06AM -0500, Chris wrote: > One final comment. It seems there was some motivation, by the PHP creators, > to institute safe mode as a fix to potential security abuses. If that was > the case, why weren't the underlying problems be removed or remedied as > opposed to letting PHP admins make the call? To remove the underlying problem, changes in Apache would have to be made. The problem is that mod_php (not necessarily PHP as CGI) runs as the same user that Apache runs as. There is nothing PHP developers can do about that. This means (assuming mod_php) that when your hosted website runs a PHP script, and another website hosted by the same company runs a PHP script, both scripts are running as the same username. This opens any number of potential for malicious or accidental access to others files. Additionally, all system calls will be called as the same user, so the server's built-in mechanisms for determining user permissions are useless. One solution is to run PHP as CGI and use suexec to cause PHP scripts to be run as specific usernames. However, there are speed and integration advantages to running as mod_php, so using CGI isn't necessarily the best solution. The other is to use safe mode, which does what it can to help solve security concerns by relying on file permissions to determine what can accessed, and by restricting things like system calls that are too potentially harmful. It's not the right way to solve the problem (as they mention on the safe mode page), but solving at the Apache level[1] may or may not be viable. Safe mode is not necessarily appropriate for all situations; on personal servers, or single-user websites, it can be too restrictive. However, for hosting companies, as others have said, not using it has the potential to make your customers very unhappy when someone else's poorly-coded script starts wreaking havoc. [1] Apache 2's "perchild" MPM looks interesting: http://httpd.apache.org/docs-2.0/mod/perchild.html When it's functional, I'm not sure if it will eliminate the need for safe mode or not. It still appears that for large hosts, managing the UIDs might be difficult. I'm by no means an apache admin, but if my hosting company has 300 vhosts, it seems like you'd have to start at least that many servers, and that only one instance will be tied to a vhost (so if one vhost is getting lots of traffic, and one is getting only a little, there won't be spare servers around to balance things out). I'm basing that all on what I read at Apache's site, so I may well be wrong. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to do this (sub selects?)
On Fri, Mar 05, 2004 at 01:53:45AM +, Richard Davey wrote: > m> I've done this with two queries, the first selecting distinct topics and > m> then running a subquery on all question/answers pertaining to that topic. I > m> was just curious if anybody was handing these situations differently. > > You should find that doing a GROUP BY and then ORDER BY on the Topic > field gives you the results back in the right sequence for what you > want. Your display life in PHP will then be much simpler. ORDER BY will definitely help, but GROUP BY will not be useful here. The original query results looked like: TOPIC QUESTIONANSWER 1 A B 1 C D 1 E F 2 G H 1 I J 2 K L 3 M N By adding "ORDER BY topic" or something similar[1] to the query, you can get your results to look like this: TOPIC QUESTIONANSWER 1 A B 1 C D 1 E F 1 I J 2 G H 2 K L 3 M N I'd also recommend adding a secondary ORDER BY to make sure that QUESTION is ordered properly. The example results wouldn't change, but presumably those aren't ordered yet. However, GROUP BY will do unexpected things to the results, since the point of this query isn't to perform aggregate operations[2] on rows (SUM, AVG, etc...), it's simply to display all the data for all questions. If you do a GROUP BY, MySQL won't quite know what to do. To get this to display properly, you'll want to keep track of what topic you previously displayed in your loop, and only display a new one if the previous one is different. Something like: '; while ($row = mysql_fetch_assoc($results)) { # for convenient variable names extract($row); # only show the header if the topic has changed if ($topic != $last_topic) { print ''.$topic.''; } print " $question$answer"; # store the topic for next time around $last_topic = $topic; } print ''; ?> HTH! [1] http://www.mysql.com/doc/en/SELECT.html [2] http://www.mysql.com/doc/en/GROUP-BY-Functions.html -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to write this correctly?
On Sat, Mar 06, 2004 at 09:34:26AM -0500, Brian V Bonini wrote: > > What to do? > > function output($data_file) > { > $file = file("data/$data_file.txt"); > > foreach($file as $value ) { > $output .= "$value"; > } > > return $output; > } > > > switch($action) { > case "people": > output('people'); > break; > case "industry": > output('industry'); > break; > case "art" > output('art') > break; > case "animals": > output('animal'); > break; > case "contact": > output('contact'); > break; > } Hrm... why the switch() statement? I can see the need for validating user-submitted data, but to make it a little more flexible, maybe something like this: To add more valid actions, you can just extend the array of valid actions, rather than adding clauses to the switch statement. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail fifth parameter
On Sun, Mar 07, 2004 at 09:51:28AM +0600, Raditha Dissanayake wrote: > It's an often overlooked fact that you can pass additional headers in > the fourth parameter. I do belive you should use \n and not \r\n > then your code will look like > > mail("[EMAIL PROTECTED]", "object", $message, > "From: [EMAIL PROTECTED] ". > "Reply-To:[EMAIL PROTECTED]". > "Return-Path: [EMAIL PROTECTED]); As mentioned in another post, the Return-Path header can and usually is overwritten by sendmail when it does the actual sending. In addition to a previous suggestion, one way to reliably set that header is to use phpmailer (http://phpmailer.sourceforge.net/) which has the option of using an smtp server rather than sendmail directly. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] perl, cgi and php
On Wed, Mar 10, 2004 at 04:07:28PM -0500, Edward Peloke wrote: > First let me say, I know very little about perl and cgi. I have a friend > who is moving his site to a new hosting company. One of his php pages has > the following line of code: > > virtual("./timeline/ganttChart.cgi?user={$gallery->session->username}"); ?> > > but when the page is displayed all that shows up is the content of the .cgi > script. Is this a configuration issue? The new hosting company's web servers don't appear to have their servers setup to parse *.cgi files through CGI. They will need to fix that, or he will need to move ganttChart.cgi into a directory that is setup to handle CGI files -- sometimes you'll have a cgi-bin directory for this purpose. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get "nice" variables from POST
On Thu, Mar 11, 2004 at 02:51:25PM +, Mike Mapsnac wrote: > I have about 10 fields in the form. And I get the fields through POST: > //Get Variable from the form > $username = $_POST['username']; > $password = $_POST['password']; > $password2 = $_POST['password2']; > $email = $_POST['email']; > $email2 = $_POST['email2']; > $nickname = $_POST['name']; > $city = $POST['city']; > $state = $_POST['state']; > $country = $_POST['country']; > $misc = $_POST['misc']; > $country = $_POST['country']; > > It works but it looks ugly. For each variable I have statemet. Is there a > way to get the variables in the loop? In addition to the other suggestions, you might use extract() on $_POST: http://www.php.net/extract To be sure you know where you're getting your variables, you could add a prefix to the variable names ('p', for example), so your vars would look like: $p_username $p_password $p_password2 etc... I personally would prefer this over register_globals because it gives me more convenient access to my variables, but I don't have the danger of $_POST variables overwriting my existing ones (assuming I don't name other variables with the p_ prefix, use the proper extract() flags, etc.). joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Certification
On Mon, Mar 15, 2004 at 09:05:42AM -0700, Sheeraz fazal wrote: > I need information about the php certification, from www.expertrating.com . > Does this site has good market reputation? I took 10 minutes yesterday and checked out one of their free tests on computer literacy or something like that. The questions were poorly worded, rife with misspellings, and had illogical choices. Some choice snippets: "This exam is best viewed using Internet Explorere 5.0 or above" Q1: "You have a mouse attached to your computer which suddenly stops working. You quickly replace the mouse with another one which has been manufactured by a different company. Will it work?" (my options are "yes" and "no". "there is no way to make an accurate guess" is not an option) Q27: "If you are looking for information about a certain subject on the Internet, what is the quickest way to get started?" Q?: "Where is the Calculator located in the Windows Program menu?" (my options were 4 different Windows menu paths) You can be the judge based on that, I suppose. If their PHP "exam" is anything like this one, though, the final certification will mean nothing except that you gave them $10. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculate
On Tue, Mar 16, 2004 at 02:35:57PM +0200, Tommi Virtanen wrote: > How I can calculate following: > > I have table: > id(int) start_date(date)end_date(date) > 001 2004-03-10 2004-03-12 > 002 2004-03-27 2004-04-02 > 003 2004-04-05 2004-04-06 > > Total count of date is 12. But how I can calculate count of > date per month? > > regards, I'm assuming this is in a MySQL table. Is that correct? This is probably something that will better be answered on a MySQL list. Assuming that it is MySQL, how are you deciding which month an item is in? What if it starts in March and ends in April? Should it be considered to be in March or April? MySQL's COUNT[1], GROUP BY[2], and DATE_FORMAT[3] will be helpful to you. Something like: SELECT COUNT(*) AS num, DATE_FORMAT(end_date, "%Y-%m") AS yearmonth FROM yourtable GROUP BY yearmonth ORDER BY num; might work[4]. [1] http://www.mysql.com/doc/en/GROUP-BY-Functions.html#IDX1452 [2] http://www.mysql.com/doc/en/SELECT.html [3] http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1341 [4] This query assumes that end_date is sufficient to determine which month something is "in". Also, it relies on some potentially MySQL-specific syntax. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calculate
On Tue, Mar 16, 2004 at 09:43:28AM -0800, Jason Davidson wrote: > Most likely im not understanding your question.. but, if you are trying > to calculate the total rows by month.. > SELECT whatever FROM table WHERE MONTH(your_date) = '03'; > > and use num_rows or row_count or whatever the php mysql function is I didn't post the original message; I was responding to Tommi, who asked about calculating the "count of date per month". Your method will have all rows returned to PHP, and require PHP to count the rows afterward. If you would do this: SELECT COUNT(whatever) FROM table WHERE MONTH(your_date) = '03'; then your result set will only have one row (the number of matching rows), and you don't need to do any additional counting work. However, all of that is for the OP, not for me, so I'm CCing the list back in. -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limiting an array to unique values
On Tue, Apr 06, 2004 at 09:27:31AM -0500, Alex Hogan wrote: > Hi All, > > I have an array that I am using as a parameter for a query in a where > clause. > > The array has values that are like this. > > Item 1 > Item 2 > Item 3 > Item 1 > Item 3 > Item 3 > Item 1 > > What I need to have is unique values only. > > Item 1 > Item 2 > Item 3 > > How can I sort out the redundant values in that array? PHP's 'array_unique' function should help: http://php.net/array_unique -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php