[PHP] Renaming Directories
I've made a small PHP script that renames the files and folders in my music library, to make them more linux-friendly. I'm running PHP 5.0.3 on version 2.6.9 kernel. What's happening is that all files and folders are renamed, except for folders whose names consist of one word only (such as Toto), which is still with a capital T. Here is the script and the result I'm getting: ?php error_reporting(E_ALL | E_STRICT); header('Content-Type: text/plain'); function clean_filename ($str) { $str = strtolower($str); $str = str_replace(' - ', '-', $str); $str = str_replace(' ', '_', $str); $str = str_replace('\'', '', $str); return $str; } function parse_dir ($dir_name) { $dir = opendir($dir_name); while (false !== ($file = readdir($dir))) { if ($file != '.' $file != '..') { $path_old = $dir_name . $file; $path_new = $dir_name . clean_filename($file); echo renaming $path_old to $path_new... ; echo rename($path_old, $path_new) ? done\n : failed\n; if (is_dir($file)) parse_dir($path_old); } } closedir($dir); } parse_dir('/shared/music/'); ? renaming /shared/music/dire_straits to /shared/music/dire_straits... done renaming /shared/music/johnny_winter to /shared/music/johnny_winter... done renaming /shared/music/pink_floyd to /shared/music/pink_floyd... done renaming /shared/music/ten_years_after to /shared/music/ten_years_after... done renaming /shared/music/the_doors to /shared/music/the_doors... done renaming /shared/music/Santana to /shared/music/santana... done renaming /shared/music/the_jimi_hendrix_experience to /shared/music/the_jimi_hendrix_experience... done renaming /shared/music/the_velvet_underground to /shared/music/the_velvet_underground... done renaming /shared/music/tim_christensen to /shared/music/tim_christensen... done renaming /shared/music/dizzy_mizz_lizzy to /shared/music/dizzy_mizz_lizzy... done renaming /shared/music/Toto to /shared/music/toto... done renaming /shared/music/Cream to /shared/music/cream... done renaming /shared/music/Filopahpos to /shared/music/filopahpos... done renaming /shared/music/bob_dylan to /shared/music/bob_dylan... done renaming /shared/music/dinojax to /shared/music/dinojax... done renaming /shared/music/red_hot_chili_peppers to /shared/music/red_hot_chili_peppers... done renaming /shared/music/peter_frampton to /shared/music/peter_frampton... done renaming /shared/music/louis_armstrong-what_a_wonderful_world.mp3 to /shared/music/louis_armstrong-what_a_wonderful_world.mp3... done As you can see, the rename() returns TRUE, but it doesn't rename the folder. I hope you guys can help me out, because otherwise I'll have to do it manually (which I'm too lazy to even consider.) Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Renaming Directories
Daniel Schierbeck wrote: I've made a small PHP script that renames the files and folders in my music library, to make them more linux-friendly. I'm running PHP 5.0.3 on version 2.6.9 kernel. What's happening is that all files and folders are renamed, except for folders whose names consist of one word only (such as Toto), which is still with a capital T. Here is the script and the result I'm getting: ?php error_reporting(E_ALL | E_STRICT); header('Content-Type: text/plain'); function clean_filename ($str) { $str = strtolower($str); $str = str_replace(' - ', '-', $str); $str = str_replace(' ', '_', $str); $str = str_replace('\'', '', $str); return $str; } function parse_dir ($dir_name) { $dir = opendir($dir_name); while (false !== ($file = readdir($dir))) { if ($file != '.' $file != '..') { $path_old = $dir_name . $file; $path_new = $dir_name . clean_filename($file); echo renaming $path_old to $path_new... ; echo rename($path_old, $path_new) ? done\n : failed\n; if (is_dir($file)) parse_dir($path_old); } } closedir($dir); } parse_dir('/shared/music/'); ? renaming /shared/music/dire_straits to /shared/music/dire_straits... done renaming /shared/music/johnny_winter to /shared/music/johnny_winter... done renaming /shared/music/pink_floyd to /shared/music/pink_floyd... done renaming /shared/music/ten_years_after to /shared/music/ten_years_after... done renaming /shared/music/the_doors to /shared/music/the_doors... done renaming /shared/music/Santana to /shared/music/santana... done renaming /shared/music/the_jimi_hendrix_experience to /shared/music/the_jimi_hendrix_experience... done renaming /shared/music/the_velvet_underground to /shared/music/the_velvet_underground... done renaming /shared/music/tim_christensen to /shared/music/tim_christensen... done renaming /shared/music/dizzy_mizz_lizzy to /shared/music/dizzy_mizz_lizzy... done renaming /shared/music/Toto to /shared/music/toto... done renaming /shared/music/Cream to /shared/music/cream... done renaming /shared/music/Filopahpos to /shared/music/filopahpos... done renaming /shared/music/bob_dylan to /shared/music/bob_dylan... done renaming /shared/music/dinojax to /shared/music/dinojax... done renaming /shared/music/red_hot_chili_peppers to /shared/music/red_hot_chili_peppers... done renaming /shared/music/peter_frampton to /shared/music/peter_frampton... done renaming /shared/music/louis_armstrong-what_a_wonderful_world.mp3 to /shared/music/louis_armstrong-what_a_wonderful_world.mp3... done As you can see, the rename() returns TRUE, but it doesn't rename the folder. I hope you guys can help me out, because otherwise I'll have to do it manually (which I'm too lazy to even consider.) Daniel Ooops, that should've been parse_dir($path_new) instead of parse_dir($path_old). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get name of extending class with static method call
Torsten Roehr wrote: Christopher Fulton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Not sure if this is the best way to do it or not, but you can do this and it should (untested code) work. class Car { function drive() { return $this-getClassName(); } function getClassName() { return Car; } } class Porshe { function getClassName() { return Porshe; } } $foo = new Porshe(); echo $foo-drive(); Of course this might work but it requires the definition of such a method in *every* class I have. Any more ideas? Thanks in advance! Torsten I'm not sure if this will work, but hey, you could give it a try. class Car { public static $className = __CLASS__; public static function drive () { return self::$className; } } class Porche extends Car { public static $className = __CLASS__; } Porche::drive(); // Should return Porche -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Get name of extending class with static method call
Christopher Fulton wrote: This should work for you then(maybe...i don't have php5 on my system, so it may not, but i think it would. http://us4.php.net/manual/en/function.get-class.php class Car { function drive() { return get_class($this); } } class Porshe { } $foo = new Porshe(); echo $foo-drive(); He needs a static function, ie Porche::drive() -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP College Scholarships?
Andrew Wickham wrote: Does anyone know of any college scholarships for PHP or Computer Science. I need some non-college specific ones. The reason I ask is obviously because I need some help going to college through scholarships, and I have been programming in PHP for about 6 years now. Please help me out guys! Andrew Wickham Sorry, I don't live in the US, so I don't know if there are any scholarships - But I'm kind of curious about what you guys pay for a college education. Are scholarships common, or do almost everyone have to pay? I come from Denmark, and our education system is entirely tax funded, so I'm unfamiliar with those things (but as I said, curious ;)) Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to argue with ASP people...
Tony Di Croce wrote: I am fairly new to PHP, but I am loving it... I have recently gotten involved in a business venture and I have been using PHP so far... Recently I have taken on a partner, and he is a big ASP guy... I am not totally against ASP, but it would have to be pretty good to get me to switch at this point (PHP seems to do everything I need)... But I will need to convince him of this... What points can I bring up in PHP's favor? In what areas does PHP trounce ASP? First of all, ASP doesn't run on anything but Windows servers (unless you're willing to use ChiliASP... *hiss*) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: wrong value from define
Arthur wrote: Hi, in the following code, i want to get a constant value from config.php. I don't receive the value, that is defined, but the name of the constant. I tested the defines in config.php by echoing all defines, and it was allright, so i'm quite confused why it doesn't work here. That's my piece of code (which is in a class in a file which is in the same dir as config.php): function reg($name, $pw, $ally, $act) { include('config.php'); echo(DB_SERV_NAME . 'br'); $dbp = mysql_connect(DB_SERV_NAME, DB_USR_NAME, DB_PW); if(!$dbp) die (MySQL-Fehler); Thats my error message: Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL Server Host 'DB_SERV_NAME' (11001) in C:\apachefriends\xampp\htdocs\alliance\script\cl.member.php on line 34 MySQL-Fehler Normally, i should get 'localhost'. Anyone who can help me? place this at the top of the file: error_reporting(E_ALL); Either you don't define the consatnts properly or the include file doesn't exist. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Replacing whole words only
Chris Boget wrote: Is there a way to replace/remove *whole* words from a phrase? For example: ? $exceptionsList = array( 'the', 'other', 'that', 'a' ); $stringToParse = 'The other lady that laughed'; if( count( $exceptionsList ) 0 ) { foreach( $exceptionsList as $exceptionPhrase ) { $stringToParse = str_replace( $exceptionPhrase, '', trim( $stringToParse )); } $retval = trim( $stringToParse ); } echo 'Retval: ' . $retval . 'br'; ? results in The or ldy lughed and not lady laughed. Using the other *_replace() functions give the same results. So is what I'm looking to do even possible? thnx, Chris $exceptions = array('the', , 'other', 'that', 'a'); $string = 'The other lady that laughed'; foreach ($exsceptions as $exception) { $string = str_replace(' ' . $exception . ' ', '', $string); } You might need to convert the string to either lower- or uppercase. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: nntp://news.php.net -- read only?
Jason Morehouse wrote: Sorry for the lame question... but I prefer to read and reply to messages via the news server. However, I can't seem to post to news.php.net. I'm using thunderbird, and have tried a few different outgoing servers, including news.php.net. Is the news server read only? I thought for sure I was able to reply on it some time ago Thanks, -J No. I'm using the news server too. It's just slow sometimes, and might throw an error. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP cross platform IDE
Craig Slusher wrote: ... Another alternative is to use Eclipse IDE with the PHPEclipse.de plugin. I've messed around with it a little bit and it's not too bad. Yeah, I'd go with Eclipse. It also integrates with CVS WebDAV (and FTP!), and have some cool features. I've tried off Zend Studio, but I thought it was slow and had a messy and ugly user interface. And hey, Eclipse is free! -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Close all open tags in HTML text
Matt Palermo wrote: I realize that I can use the strip_tags function to remove HTML. But I don't want to remove HTML tags. I just want to make sure all open HTML tags are closed. For example if they user submits HTML with a table tag and never closes it, then the rest of the page will look screwed up. I still want to allow them to use HTML, but I want to close tags that were left open by them. This way it allows them to use HTML and it won't screw up the rest of the page. Thanks, Matt Richard Lynch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Matt Palermo wrote: I would like to leave any HTML in there, Do you *TRUST* the people typing the HTML to not attack your server, or others, with cross-site scripting attacks? If not, go re-read the manual about strip_tags, and pay particular attention to the second, optional, argument. but just make sure that ending tags exist, so it doesn't screw up the rest of the page. Strip tags would just wipe out the HTML rather than allowing it and ending it safely. Strip tags will allow you to wipe out *DANGEROUS* HTML which will make your web server a source of problems not only to you, but to me as well. Please use strip_tags to allow only the tags you *NEED* the users to be able to use. It will only take you seconds, and it will save you (and us) a lot of grief in the long run. -- Like Music? http://l-i-e.com/artists.htm You still need to control it. This would certainly fuck up your page: div style=position: absolute; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; background-color: red;/div -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Close all open tags in HTML text
Matt Palermo wrote: I am allowing users to imput HTML code into a textarea. After they input this, I wany to output their HTML to the browser. In order for the document to be safe, I need to close all open HTML tags that have been left open by the user, along with any open comments. Is there a way to take an HTML string and add closing tags and comments to it if needed? Thanks, Matt I would use a regular expression to grab the valid opening and closing HTML tags, and use something á la htmlentities() on the rest of the document. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Getting static member for a class which name is stored in a variable
Daniel Schierbeck wrote: public static function getData () Ooops, the method shouldn't have been static :) -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Happy Thanksgiving
John Nichel wrote: Happy Turkey Day ladies and gents. Disclaimer : If you are not in the US, or do not celebrate Thanksgiving, you are still allowed to have a 'happy' day. ;) I just can't wait 'til Talk Like A Pirate Day (September 19 if I remember correctly)! Arrr, shiver me timbers! There be treasure in them thar hills! And no, I'm not from the US ;) -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Getting static member for a class which name is stored in a variable
Francisco M. Marzoa Alonso wrote: I've code like follows: ?php class TestClass { public static $Data = 'This is the data'; } $Obj = new TestClass (); $ClassName = get_class ($Obj); echo $ClassName::$Data; ? It gives me an error like: Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM ... I've found googling that it means that those '::' are unexpected. So, How can I get an static member for a class which name is stored in a variable? Thx. I'd make a method in the class that returned the static variable: class TestClass { public static $data = 'This is the data'; public static function getData () { return self::$data; } } $obj = new TestClass(); echo $obj-getData(); -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to $_POST from a grid
Stuart Felenstein wrote: I have set up a record grid, where the user may see a list of their records. Repeat region, etc. There is a button next to each record the user may click to allow them to update the particular record. This all worked fine with $_GET where I did a link on the button to send the PrimaryID over. Now I'm attempting to use $_POST and not having the same success. I moved the grid into a form and have a submit button now for the update button. Since the grid only is echos of the recordset fields, how does it know the correct PrimaryID to send when I hit the submit button. I'm thinking this is perhaps my problem. Can anyone help please Stuart I'd go with a POST form and a JavaScript form name=grid method=post input type=hidden name=primary_id / input type=button onclick=document.grid['hidden'].value='123' value=foobar / /form Or something. I'm not really that good with JavaScripts. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text Parser
Jesse Castro wrote: [snip] I need to get a procedure able to do this: 1) Receive a string. For example: name age address location. 2) Process that string, inserting comas between the words in the middle. For example: name,age,address,location. It´s important that the comas must be inserted after the first word, and before the last one. 3) Return that string. [/snip] $old = name age address location; $new = str_replace( , ,, $old); Why not go with 4 strings? If the string is like this it won't work as intended: $string = 'John Doe Fooroad 11 35 US'; // John,Doe,Fooroad,11,35,US -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text Parser
John Nichel wrote: Pablo D Marotta wrote: Hi there... I need to get a procedure able to do this: 1) Receive a string. For example: name age address location. 2) Process that string, inserting comas between the words in the middle. For example: name,age,address,location. It´s important that the comas must be inserted after the first word, and before the last one. 3) Return that string. Dah, dah, dah This looks like a job for Captain explode(), and his trusty sidekick, Kid implode(). Arrr ye swashbuckler, ye be forgettin' me, the pirate! Arrr, there be treasure in them thar hills! Lootin' time! Arrr! -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Tabs or Spaces?
Daniel Schierbeck wrote: Hello there! There seems to be some tendency towards using spaces instead of tabs when indenting PHP code - personally i can't come up with any reason not to use tabs. I was just wondering if any of you freakees had some sort of explanation... Wow, didn't mean to start a major debate :x Thanks, now i know (switching to spaces). -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Tabs or Spaces?
Hello there! There seems to be some tendency towards using spaces instead of tabs when indenting PHP code - personally i can't come up with any reason not to use tabs. I was just wondering if any of you freakees had some sort of explanation... -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Simple coding question
Octavian Rasnita wrote: Hi all, Please tell me which is the shortest method for writing the following code: $var = $_GET['var'] || 'value'; I want the program to put the value value in the variable $var if the array element 'var' is not defined or in case it is 0 and I would like to avoid using that long style with if (..) {...} else {...}... Thank you. Teddy Like the others said, use the ? : method: $var = (isset($_GET['var']) $_GET['var']) ? $_GET['var'] : 'value'; -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Silly OOP question
Brent Clements wrote: I've always wondered this about OOP and maybe you guys can answer this question. I'm writing a php application and I'm trying to figure out the correct way to right the oop part of this application. for instance. I have a project.class file that has functions for dealing with individual projects because you break down ideas into singular entities in OOP(as I understand it) But what if I wanted to deal with multiple projects such as getting a list of the projects in my database, should I create a function in the project.class to handle the now plural request, or should I create a projects.class file that has a function called getProjects. Hopefully I'm explaining this question right. It makes sense in my own head. :-) Thanks, Brent Well, if I get you right, you have a class named Project holds information about a project. Now you want a list of the current projects. I'd make a new class, named ProjectList or something similar, that can be used to administrate your projects. class Project { public $name;// The project's name public $ownerID; // The user ID of the project's owner /* The constructor. Note: this only works in PHP5 */ public function __construct ($id) { $db = mysql_connect(); // Get project info... $this-name= $result['name']; $this-ownerID = $result['owner']; } } class ProjectList { public $projects = array(); public function __construct () { $db = mysql_connect(); $query = mysql_query('SELECT id FROM projects'); $result = mysql_fetch_array($query); foreach ($result as $project_id) { $this-projects[$project_id] = new Project($project_id); } } public function listProjects () { return $this-projects; } public function addProject ($name, $owner) { // ... } public function deleteProject ($id) { // ... } } -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Test post from a new client
Robb Kerr wrote: This is a test post from a new client. I'm trying to decide whether or not to keep it. Please post a reply so that I can see how it shows up. Thanx, Robb FUBAR -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Silly OOP question
Brent Clements wrote: I've always wondered this about OOP and maybe you guys can answer this question. I'm writing a php application and I'm trying to figure out the correct way to right the oop part of this application. for instance. I have a project.class file that has functions for dealing with individual projects because you break down ideas into singular entities in OOP(as I understand it) But what if I wanted to deal with multiple projects such as getting a list of the projects in my database, should I create a function in the project.class to handle the now plural request, or should I create a projects.class file that has a function called getProjects. Hopefully I'm explaining this question right. It makes sense in my own head. :-) Thanks, Brent Who cares whether or not PHP is an object oriented language? If it has OO features, you can call it whatever you like, I'd still be happy. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Silly OOP question
Klaus Reimer wrote: you can implement it completely statically so you don't need to instanciate the class Well, it might be useful to have more than one list of projects, ie if you want all design-related projects, or all PHP-projects. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: User's language settings
Dmitri Pissarenko wrote: Hello! I have a web-site, part of which is in Russian and another part in English. English and Russian parts are located in different directories. The web-site is static. I want to create a PHP file, which redirects the user from /index.php to /ru/index.html, when his primary language is Russian and to /en/index.html, when his primary language is non-Russian. In other words: ?php if ($languageRussian) { header(Location: http://dapissarenko.com/ru/index.html;); } else { header(Location: http://dapissarenko.com/en/index.html;); } exit; ? How can I determine user's primary language? Thanks! dap I don't think it's possible. You can, however, ask the user to select which language he wishes to see, then store that option in a cookie so he doesn't have to do it every time he visits the site. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] User's language settings
Marek Kilimajer wrote: Dmitri Pissarenko wrote: Hello! I have a web-site, part of which is in Russian and another part in English. English and Russian parts are located in different directories. The web-site is static. I want to create a PHP file, which redirects the user from /index.php to /ru/index.html, when his primary language is Russian and to /en/index.html, when his primary language is non-Russian. In other words: ?php if ($languageRussian) { header(Location: http://dapissarenko.com/ru/index.html;); } else { header(Location: http://dapissarenko.com/en/index.html;); } exit; ? How can I determine user's primary language? Thanks! dap $_SERVER[HTTP_ACCEPT_LANGUAGE] - string with user's language preferences. However only a fraction of users willingly set it, so many times it will be on its default value, english even for russian speaking visitors. Yup. I think it's better if you let the visitors decide. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Question: Passing error messages
Stuart Felenstein wrote: I've started getting into the habit of passing error messages through session variables, particularly on redirects. From some peoples reaction on this list I gather it's not the best practice. What is an alternative way ? I believe it's through a URL. not sure how to go about that method Stuart I'm not quite getting what you're saying - are you sending the error messages on to a new page?! The usual and simple way of doing this is the good 'ol OR operator: do_something() or die('Couldn\'t do it, sorry...'); Well, maybe an IF then: if (!do_something()) { exit('Still can\' do it...'); } But there are also much more sophisticated ways of doing it. Clarify exactly what you're trying to do, and we'll get back to them. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Question: Passing error messages
Stuart Felenstein wrote: I'm saying, currently if there is an error and the script needs to exit, I'm doing this : if ..error { $_SESSION['ErMsg'] = Submit Failure; header (location: ) exit; } I want to know what alternatives there are to error messages aside from using a session variable. Thank you , Stuart Where are you redirecting the client to? An error page? -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: VOTE TODAY
Ryan A wrote: switch ($the_choice) { case Daniel_Schierbeck_1: echo 'Didnt read previous thread and comes voiceing his political opinions like a jackass on a high traffic PHP mailing list which people from different countries other than the states receive'; break; case Daniel_Schierbeck_2: echo 'Just a moron'; break; default: echo 'both of the above'; } 1) I'm not American. 2) Nice job with the constants, though I usually use upper case characters only... 3) Don't get personal, nobody likes a bitch. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] VOTE TODAY
Ryan A wrote: On 11/2/2004 6:34:43 PM, ApexEleven ([EMAIL PROTECTED]) wrote: I can't wait for the replies... Heres one, I vote you drive yourself and your family as fast as possible on the freeway then close your eyes and wave both your hands in the air while counting from 1000 to 1, be sure to keep the accelerator to the floor. -Ryan Wow, I can feel the positive vibes coming from your posts! Halelujah! -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: blank function parameters
Giles Roadnight wrote: Hello If I defined a function with 4 parameters but only pass 3 I get an error. Is there anyway around this? I want to be able to set the missing parameter to a default value if it is not passed which works ok but How do I get rid of the error message? Thanks Giles Roadnight http://giles.roadnight.name If you want an argument to be optional and still be able to check whether or not it's been set, you can use NULL as the default value: function foobar ($a, $b, $c = null) { if (isset($c)) { echo 'The third argument was set'; } } -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: blank function parameters
Matthew Weier O'Phinney wrote: * Daniel Schierbeck [EMAIL PROTECTED]: Giles Roadnight wrote: If I defined a function with 4 parameters but only pass 3 I get an error. Is there anyway around this? I want to be able to set the missing parameter to a default value if it is not passed which works ok but How do I get rid of the error message? If you want an argument to be optional and still be able to check whether or not it's been set, you can use NULL as the default value: function foobar ($a, $b, $c = null) { if (isset($c)) { echo 'The third argument was set'; } } That check should be for 'is_null($c)' as the default value of $c will be null, and it will be always set, even if not sent. isset(null) evaluates to false... -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: GUI editor for php?
Andy B wrote: Hi. Is there any GUI editors out there for php? if so does anybody know of a good one that doesnt cost a ton of money?? I'd go with Eclipse (http://eclipse.org) with either PHP-Eclipse (http://phpeclipse.org) or Xored Trustudio (http://xored.com). They're all free of charge. The two latter are plugins for the Eclipse framework (the first). -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: VOTE TODAY
Apexeleven wrote: I can't wait for the replies... Vote? What vote? Just kidding... switch ($candidate) { case CANDIDATE_BUSH: echo 'Oh shit, 4 more years...'; break; case CANDIDATE_KERRY: echo 'Well, he\'s the lesser evil...'; break; case CANDIDATE_NADER: default: echo 'Didn\'t see *that* one coming, did you?'; } -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Matching *exact* string?
Nick Wilson wrote: hello all I am foreach()ing through an array of ip addresses in a 'ban script' and have the following php code: foreach($ips as $ip) { preg_match(/$ip/, $_SERVER[REMOTE_ADDR]); $ban = TRUE; } This is great, but if 127.0.0 were in the ban list (for example) it would still produce a ban as it partially matches. How can I alter the above so that only *exact* matches are banned? Much thanks! I'd rather go with something like this: $banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) { die('Dude, you\'re banned!'); } But if I were you I'd choose something more advanced. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Matching *exact* string?
Daniel Schierbeck wrote: Nick Wilson wrote: hello all I am foreach()ing through an array of ip addresses in a 'ban script' and have the following php code: foreach($ips as $ip) { preg_match(/$ip/, $_SERVER[REMOTE_ADDR]); $ban = TRUE; } This is great, but if 127.0.0 were in the ban list (for example) it would still produce a ban as it partially matches. How can I alter the above so that only *exact* matches are banned? Much thanks! I'd rather go with something like this: $banned_ips = array('123.123.123.123', '321.321.321.321'); // Banned IPs if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) { die('Dude, you\'re banned!'); } But if I were you I'd choose something more advanced. And yes, I'm aware of the fact that 321.321.321.321 isn't a valid IP... -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: best php script that counts current online users, question.
Louie Miranda wrote: Hi, i got tired testing free php scripts that does count current online users and i could not find the best one yet. maybe someone can help me. im looking for a current counter for online users, php script that does count even if its inside a proxy with one ip. i can't find one. Dunno 'bout the proxy part, but can't you just have a MySQL table like this: id INT; ip VARCHAR(15); time DATETIME; PRIMARY KEY id Then check if the client IP exists in the table upon page load. If it does, update the timestamp. Otherwise insert a new row. After the query you delete all rows that are more than 5 or so minutes old. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: overiding functions (constructors mostly)
M Saleh Eg wrote: OR you could control ur method and have optional arguments in ur argument list and decide what to do according to that. e.g. public function _construct($param1=0, $param2=, $param3=null) { if($param1) if($param2) if($param3) } $obj=new className(1); //Or $obj=new className(1,hello); //Or $obj=new className(0,,some_value); Bottom Line: Optional arguments might be a workaround lack of polymorphism sometimes ! Better use if (isset($param1)) { ... then, otherwise values such as 0 will cause difficulties. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: overiding functions (constructors mostly)
M Saleh Eg wrote: Exactly Daniel ! I should've mentioned that too. Thanx for making it clear. No problem 8) -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP Crypt on MacOSX
Kris wrote: I recently moved a site to a MacOSX based Apache/PHP server. Apparently crypt only uses DES. I read somewhere that there is no way to get it use use MD5, which sounds hard to beleive considering the OS is BSD based. So.. here is my dilema.. My db contains usernames and passwords. The passwords are MD5 $1ljdslkjdsf$lkjdsaflkjdsf (created by crypt().) So on this new box, new accounts created get DES passwords. I just as well prefer to not see any DES encryptions used in this db. Any Mac OSX'ers in here that may have a solution? All my users recreating new passwords for their account is not an option. Thanks for any ideas, Kris Can't you just use the db's (i assume you use MySQL, most do) built-in MD5 function? SELECT id, username FROM users WHERE username LIKE 'myuser' AND password = MD5('mypass') LIMIT 1 -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP5 CLI Custom Error Reporting Doesn't Work as Expected
Daniel Talsky wrote: Included is my reproduce code. I'm trying to write a custom error logger for my PHP CLI script. The main problem is that when I try something like a failed require() statement, my custom error reporting function tells me it got an E_WARNING, but it stops program execution, which is not what the docs say it should do. When I try some other fatal error like trying to call an undefined function foobar(), then it doesn't run my custom error loggin function at all, just stops program execution. I tried to report this as a bug, and it was closed with no explanation...this is driving me to the brink of sanity. Can anyone help? #!/usr/local/bin/php -c /usr/local/etc/php.ini ?php function pv_shell_error_logger( $errno, $errstr, $errfile, $errline){ switch ($errno){ case E_ERROR: print('E_ERROR'.\n); break; case E_WARNING: print('E_WARNING'.\n); break; default: print('OTHER:'.$errno.\n); break; } return true; } error_reporting(0); // set to the user defined error handler set_error_handler(pv_shell_error_logger, (E_ALL)); // FIRST TEST, PRINTS 'E_WARNING' // But also stops program execution even though I'm not doing anything. //require ('foo'); // FIRST TEST, PRINTS NOTHING // And also stops program execution even though I'm not doing anything. //foobar(); ? As far as I know the only errors you can handle through a user-defined function are of levels E_USER_ERROR, E_USER_WARNING and E_USER_NOTICE. php.net (http://dk2.php.net/manual/en/function.set-error-handler.php) says this: Note: The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and E_STRICT. -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: overiding functions (constructors mostly)
Walter Wojcik wrote: I want to override the constructor for a class i am writing but when i try it says i cant redefine it. Is the a whay to have two (or more) functions with the same name that accept different agrumants and calls the right one based on the arguments (it would have to be based on number of args because of the loose typing of php.). Knowledge is power, Those who have it must share with those who don't -Walter Wojcik - Do you Yahoo!? vote.yahoo.com - Register online to vote today! No. But you can use func_num_args() to decide how many arguments the constructor (or any other function) was called with, and then make your decisions. class Foo { public function __construct () { if (func_num_args() 2) { $this-one(func_get_args()); } else { $this-two(func_get_args()); } } protected function one ($args) { // foo } protected function two ($args) { // bar } } -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Mac OS X and Editor
Jonel Rienton wrote: Hi guys, I just like to ask those using Macs here as to what editor and/or IDE they are using for writing PHP codes. Thanks and regards to all. Jonel I use the Eclipse IDE (www.eclipse.org) with phpEclipse (www.phpeclipse.org) or Xored Trustudio (www.xored.com) on Windows (hey, I'm poor), but the Eclipse IDE is cross-platform (so are the plugins as far is I know.) -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mac OS X and Editor
James McGlinn wrote: I'm using Zend Studio (ZDE) - it works as well as any I've tried. It's significantly faster than Eclipse too (on a G4 PowerBook 1.33Ghz/512MB RAM). Hmm, maybe (have you tried out Eclipse 3.0?), but I still find the interface of Eclipse superior to Zend Studio's (that's just plain ugly and confusing) - plus, it's free! And open-source! Yay! -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Referencing a constant class variable
Greg Donald wrote: On Wed, 6 Oct 2004 13:02:18 -0500, Greg Donald [EMAIL PROTECTED] wrote: On Wed, 6 Oct 2004 11:08:22 -0500, Chris Boget [EMAIL PROTECTED] wrote: If I have a class that looks like this: class MyClass { var $MyClassVar = Bob; } is there a way to reference that variable w/o instantiating MyClass? I've tried: MyClass::MyClassVar That's wrong, I was thinking of functions. Sorry. Seems you have to instantiate the class. class MyClass { var $MyClassVar = Bob; } $class = new MyClass; echo $class-MyClassVar; I believe you can make the property static (at least in PHP5): class MyClass { public static $myClassVar = Bob; } echo MyClass::$myClassVar; // Bob -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: output a PDF, over header(). causes corruption on the file?
Louie Miranda wrote: Im trying to output a pdf over a browser so i can hide the url link to it. but this one causes corruption. Try this.. http://dev.axishift.com/php/getpdf.php i got this part.. Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later. but im using netscape, and it still has error. here's the basic source for it.. ?php // We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename=downloaded.pdf'); // The PDF source is in original.pdf readfile('original.pdf'); ? what other alternatives can you suggest? i need this asap! please help. Are you sure that you don't have any whitespace before or after the PHP tags? Try using exit(); after readfile(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: set multiple variables
Argesson wrote: try this: if ($REMOTE_ADDR == 212.3.54.65 $REMOTE_ADDR == 212.3.54.66) Joe Szilagyi wrote: Hi, I have this working: if ($REMOTE_ADDR == 212.3.54.65) { header(Location: http://www.google.com/search?q=huzzah;); Redirect browser exit; } But I want to specify multiple IPs. What's the best recommended way for doing that? thanks Joe Make that: if ($REMOTE_ADDR == 212.3.54.65 || $REMOTE_ADDR == 212.3.54.66) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: set multiple variables
Matthew Fonda wrote: On Sun, 2004-10-03 at 04:39, Graham Cossey wrote: isn't the || same as ? Or I missed something? No, || is OR, and is AND Check out http://www.php.net/manual/en/language.operators.logical.php Wll - sort of. The precedence level can be tricky, sometimes || doesn't act like or (and the same with and and). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Naming conventions
Jensen, Kimberlee [EMAIL PROTECTED] wrote: What do you use for your naming conventions for variables functions classes I'm trying to tell my students what the standard is currently. Are people using camel case or underscores or both? I use this: $a_variable ClassName a_function() aMethod() -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Suggestion for IN()
Jay Blanchard wrote: You could write a function and share it with the rest of us! function between ($var, $min, $max) { return ($var $min $var $max) ? TRUE : FALSE; } function in () { if (func_num_args() 2) trigger_error('You must provide at least one argument for in()', E_USER_WARNING); $haystack = func_get_args(); $needle = array_shift($haystack); return in_array($needle, $haystack) ? TRUE : FALSE; } if (in('foo', 'bar', 'foobar', 'foo')) //... TRUE if (in('foo', 'bar', 'foobar', 'baz')) //... FALSE if (between(15, 10, 20)) //... TRUE I'm not sure if you want = and = instead in between(), but you can just change it yourself. Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Suggestion for IN()
Christophe Chisogne wrote: Daniel Schierbeck wrote: return ($var $min $var $max) ? TRUE : FALSE; (...) return in_array($needle, $haystack) ? TRUE : FALSE; You can return booleans without comparing them to true/false: return $var $min $var $max; return in_array($needle, $haystack); Christophe Thanks, nicely spotted there. Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: interesting behavior of ob_end_flush() in __destruct()
Arzed wrote: it seems that php first ends output buffering and then calls then destrcuts the objects. so the output buffering is still ended when the destructor is calles. one has to unset the object to reverse that order manually. I've encountered the same problem. It would be nice if there was an option to keep the buffered output, even after script termination. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: New PHP tutorial - suggestions welcome
Paul Hudson wrote: I've written a short PHP tutorial and am looking for input - does it cover enough ground? Is it hard to use as a reference? Does it get too technical? Anyway, if you have any ideas as to how it can be improved, I'd be happy to hear from you. The URL is http://www.hudzilla.org/php and my email address is [EMAIL PROTECTED] Looks nice :l One thing: replace weakly typed with loosely typed in http://www.hudzilla.org/php/3_1_0.php (after the first red box) Good job, Scotty! Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_connect does not connect
Sam Hobbs wrote: Steve Brown [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sam, if you wouldn't mind answering a question: are you still unable to connect to your mysql server? I am able to connect now. I'm sorry that you feel its a time-consuming process. I'm sorry that you are confused about the involvement of the firewall. I'm sorry that you feel you know better than everyone on this list. Just try this and prove us wrong. The problem is that people's insistance. It was people's reaction when I said I thought it was not relevant. There was a lot of stuff said that was unnecessary. People could have simply said to try it, without the criticism. To the extent that I was wrong, the apporopriate thing to do is to state whatever facts are relevant and then give me a chance to use that information. I have posted over 12,000 messages in the CodeGuru.com Visual C++ forum, and about 99% of the messages were efforts to help people. I know that there are people that will not listen. When a person will not listen, it is a big mistake to insult them. The attitude in this group would cause a serious flame war if someone were truly not listening. I'm SO not listening to you... ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Highest Key in an Array
I've been looking at php.net, but i couldn't find what i'm searching for. I have a numeric array, and i'd like to get the highest key. E.g. $arr = array(3 = foo, 7 = bar, 43 = foobar); What i want is a function that, in this case, returns 43. Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Highest Key in an Array
Trevor Gryffyn wrote: Or... $highestkey = max(array_keys($arr)); -Original Message- From: Martin Holm [mailto:[EMAIL PROTECTED] Sent: Friday, September 17, 2004 11:11 AM To: Daniel Schierbeck Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Highest Key in an Array Daniel Schierbeck wrote: I've been looking at php.net, but i couldn't find what i'm searching for. I have a numeric array, and i'd like to get the highest key. E.g. $arr = array(3 = foo, 7 = bar, 43 = foobar); What i want is a function that, in this case, returns 43. Daniel Schierbeck $arr = array(3 = foo, 7 = bar, 43 = foobar); krsort($arr); $highestkey = key($arr); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Damn you're fast! Thanks guys, it's all yubbely-dubbely now! Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Highest Key in an Array
I'm using it for the Wiki (thanks for that as well guys): http://aoide.1go.dk/lab/compare.php5 Source: http://aoide.1go.dk/lab/compare.source.php5 (it's just a test) Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: iguanahost - anyone else being plagued?
Nick Wilson wrote: Anyone else getting these infuriating italian messages about some muppet that doesnt exist? 'desintione non existente'? I've written to [EMAIL PROTECTED] but no joy, everytime i post on the php list i get half a dozen of the damn things... Yup, guess some Italian 1337 h4x0r has some shit going on... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] JDBC Driver for MySQL
I'm sorry if this is off-topic, but i figured this was the best place to ask: I've begun using the Eclipse IDE, and has downloaded the Quantum DB plugin. It says that i need a JDBC driver in order to connect to a remote MySQL database - where do i get that? I've looked at mysql.com, but i couldn't find anything (i might just be stupid ;)). Hope some of you know :) PS. And thanks to the guy that recommended Eclipse in this list - it rocks! Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] JDBC Driver for MySQL
Manoj Nahar wrote: see this link http://dev.mysql.com/downloads/connector/j/3.0.html official mysql jdbc driver. PS. Give google a chance. On Sun, 12 Sep 2004 15:52:12 +0200, Daniel Schierbeck [EMAIL PROTECTED] wrote: I'm sorry if this is off-topic, but i figured this was the best place to ask: I've begun using the Eclipse IDE, and has downloaded the Quantum DB plugin. It says that i need a JDBC driver in order to connect to a remote MySQL database - where do i get that? I've looked at mysql.com, but i couldn't find anything (i might just be stupid ;)). Hope some of you know :) PS. And thanks to the guy that recommended Eclipse in this list - it rocks! Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You're my savior! Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-User Text-Editing
Okay, i got the general idea, now it all comes down to the actual writing. I'm making a function that compares two strings (the one in the source i read used an exec() call, but i'd like to do it all in PHP) per-line. This poses some difficulties. Here's the scenario: I want to determine whether or not two lines are identical. If they're not: - Has the line simply been edited? - Is it a completely new line? - Has the line been deleted? To do so i'll have to run a loop, checking each line. But here's where the problem is: ?php $str1 = NEWTXT Once there was a Bar It was red It had some Foo Underneath its Foobar NEWTXT; $str2 = OLDTXT Once there was a Bar It had some Foo Underneath its Foobar OLDTXT; $arr1 = explode('\n', $str1); $arr2 = explode('\n', $str2); $count = 0; foreach ($arr1 as $line_num = $line) { if (isset($arr2[$count] ($line === $arr2[$count]))) { echo Unchanged \ . $line . \\n; } elseif ($line !== $arr2[$count]) { echo Changed to \ . $line . \ from \ . $arr2[$count] . \\n; } elseif (!isset($arr2[$count])) { echo Added \ . $line . \, was . $arr2[$count] . \\n; } $count++; } ? Then i'd get something like this: Unchanged Once there was a Bar Changed to It was red from It had some Foo Changed to It had some Foo from Underneath its Foobar Added Underneath its Foobar Where the second, third and fourth line is wrong - i added a line between There was a Bar and It had some Foo... How should i do this? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 - How Do I Let Users Download Music Files?
[EMAIL PROTECTED] wrote: Thanks Anders and Daniel. Daniel, I like your approach. I want to make it as secure as possible. I'm going to place the files outside the web directory and use authentication to approve that the user can download some particular song. I didn't know you could do a forced download. I will definitely have to try that. Thanks again. Nilaab No problem mate, and by the way, i think a friend of mine has a site that streams mp3 files - I'll ask him out about it. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 - How Do I Let Users Download Music Files?
[EMAIL PROTECTED] wrote: Thanks Anders and Daniel. Daniel, I like your approach. I want to make it as secure as possible. I'm going to place the files outside the web directory and use authentication to approve that the user can download some particular song. I didn't know you could do a forced download. I will definitely have to try that. Thanks again. Nilaab It seems that you can just replace the content-type of my previous example with: audio/mpegurl That should force a stream (haven't tested it though). Good luck -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 - How Do I Let Users Download Music Files?
Daniel Schierbeck wrote: [EMAIL PROTECTED] wrote: Thanks Anders and Daniel. Daniel, I like your approach. I want to make it as secure as possible. I'm going to place the files outside the web directory and use authentication to approve that the user can download some particular song. I didn't know you could do a forced download. I will definitely have to try that. Thanks again. Nilaab It seems that you can just replace the content-type of my previous example with: audio/mpegurl That should force a stream (haven't tested it though). Good luck make that audio/mpeg :) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 - How Do I Let Users Download Music Files?
John Nichel wrote: Daniel Schierbeck wrote: snip Hey Daniel, do me a favor if you would, and add a year to the date on your computer. Thanks. Oooops... Sorry, i have a crappy, ehh, legal *cough* version of Adobe Photoshop, it won't work unless i put the time on my PC back a year, and sometimes i forget to put it back... :) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multi-User Text-Editing
I'm developing a site with information about songs, albums and artists. I would like to have the song lyrics as well, but i don't know how i should approach it. What i want is basically a way for many users to update, add or delete parts of a text (the lyric). It will probably only be 'trusted' users that'll be able to do it (users that has added more than x artists/albums/songs). How can i make a CVS-like system, where you can see the changes people made, maybe roll back to an earlier version etc. etc.? I think i'll use MySQL, but if you think it's easier to use XML or something else, that'll be fine with me (as long as it's generally available). Thank you in advance guys :) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-User Text-Editing
Michal Migurski wrote: What i want is basically a way for many users to update, add or delete parts of a text (the lyric). It will probably only be 'trusted' users that'll be able to do it (users that has added more than x artists/albums/songs). How can i make a CVS-like system, where you can see the changes people made, maybe roll back to an earlier version etc. etc.? You've just described a wiki - one example of a wiki that is written in PHP and MySQL is http://tavi.sourceforge.net. The code is a little spaghetti-like, but you should be able to look through the database schema to understand how they implement the multi-user text editing, and how to handle the related problems of locking and revision control. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html Thanks, I'll look into it. Also the CVS-in-PHP thing. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-User Text-Editing
Michal Migurski wrote: What i want is basically a way for many users to update, add or delete parts of a text (the lyric). It will probably only be 'trusted' users that'll be able to do it (users that has added more than x artists/albums/songs). How can i make a CVS-like system, where you can see the changes people made, maybe roll back to an earlier version etc. etc.? You've just described a wiki - one example of a wiki that is written in PHP and MySQL is http://tavi.sourceforge.net. The code is a little spaghetti-like, but you should be able to look through the database schema to understand how they implement the multi-user text editing, and how to handle the related problems of locking and revision control. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html Wow, confusing code - but i think i got the idea. Just one thing: After reading the code, it seems to me that every time someone makes a change to a record, a new row is inserted into the DB with the full text of the edited record - not just the changes. I saw that there was an automatic expiration function, but still, wouldn't it be a drag for the server? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 - How Do I Let Users Download Music Files?
[EMAIL PROTECTED] wrote: Hello everyone, I want to build a music site, all copyrights intact, and I want users to be able to download mp3 or realplayer files using a one-click link. When they click on a link they will simply be given a typical download window to save that music file. How do I go about doing that and how should my file structure work? What should the link include? Is it possible to just say, for example, http://somesite.com/music/something.mp3? If you want more control over the files you could have the mp3's in a private directory, then using PHP to force a download. There are some other threads about the Content-Type header, which is probably what you're looking for Imagine that your file, 3416.mp3 is in /songs. 3416 is the song ID, so you can grab info such as artist, album and song name from a DB. Below is download.php, to download 3416.mp3, you should type download.php?file=3416 ?php if (!isset($_GET['file']) or !file_exists('songs/' . $_GET['file'] . '.mp3')) { die(No file selected); } else { $file = $_GET['file']; } $db = mysql_connect(); // More DB stuff $artist = $row['artist']; // The artist name from the DB $album = $row['album']; // ... $song = $row['song']; // ... $filename = $artist . '-' . $album . '-' . $song . '.mp3'; header('Content-Type: application/force-download'); header('Content-Length: ' . filesize('songs/'.$file.'.mp3')); header('Content-Disposition: attachment; filename=' . $filename . ''); header('Content-Transfer-Encoding: binary'); readfile('songs/' . $file . 'mp3'); exit(); ? Also, if I wanted them to listen to streamed music does PHP have any specialized functions I could use to achieve that? You should take a look at the Ming library and the mp3 stream function (http://www.php.net/manual/en/function.swfmovie.streammp3.php). It's a bit tricky though, but i can't think of anything else. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: tool to increase your web sites profitability
Theeb Basheer wrote: Dear Friend, Would you be excited if I told that YOU COULD EARN $3,500 EVERY DAY from a web site that gets only 100 visitors a day... and sells a product that costs less than $150? You could be earning over $100,000 every month! This isn't hype. And this certainly is no joke! It's rare that I am this impressed by a marketing technique... but this literally blew my mind! This is information that we are sharing with our subscribers only -- so listen up! I watched in utter amazement as this guy (who we'll call Mr. H for the moment) turned... 100 visitors a day into $1,277,500 a year in profits! ... and he's just starting out! Get this -- he expects to be earning $10,000,000 a year when he's finished implementing this SIMPLE, yet totally INGENIOUS MARKETING STRATEGY! This isn't about banner advertising... search engines... or newsgroups. And it's certainly not about some rare, high priced product... or huge volumes of traffic. It's about none of that. This guy has developed AN ENTIRELY NEW WAY TO MARKET YOUR BUSINESS on the Internet! And he's blown the gimmicky theories of those so-called marketing experts right out of the water! He's proven that -- using this one totally brilliant marketing strategy -- the small business owner can EARN HUGE PROFITS CONSISTENTLY! Day after day, month after month... the sales just keep rolling in! What's his secret? I can't tell you here. There's not enough room in this e-mail! It took a 90-minute audiotape to capture the original interview with this marketing genius... and ANOTHER tape to answer the questions of 130 participants! However, you're in luck! For the FIRST TIME EVER, Mr. H's blueprint for success is being released... Like I said before, it's really rare that I endorse marketing material... but as soon as I heard his unique success formula, I knew that I had a responsibility to share this EXTREMELY PROFITABLE information with our subscribers. This guy has really proven that ANY SMALL ONLINE BUSINESS can earn big money... using the right approach! To begin learning Mr. H's proven techniques and start making your web site a huge success story, I highly recommend that you check out http://www.marketingtips.com/t.cgi/823254/directsales And don't hesitate! This limited-time opportunity to discover his secrets will only be available for a few more days! Sincerely, theeb basheer Mooo! -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: ERROR IN THIS CODE
Jorge wrote: the problem is that when i do a echo shows me: SELECT * FROM oposicions WHERE id = '' - Original Message - From: raditha dissanayake [EMAIL PROTECTED] To: Jorge [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, September 05, 2004 6:01 PM Subject: Re: Fw: [PHP] ERROR IN THIS CODE Is this part of a guessing game? do you want us to guess the error message you are seeing? Jorge wrote: include('include/conexion.php'); include('include/conf.php'); $sql = SELECT * FROM oposicions WHERE id = '$id'; I think that the problem is here. $result = mysql_query($sql, $link); while( ($row=mysql_fetch_object($result)) ) { $nome = $row-nome; In my database exist the table oposicions with a field called id.My php version es 4.3.38 and of mysql is 3.23.58 thank you in advance -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try using $_GET['id'] instead of $id. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP IDE for OS X
Andrei Verovski wrote: Hi, Jastin, Just try Eclipse (www.eclipse.org) and PHP plugin called phpeclipse (available at sourceforge.net). Works great on ALL platforms, including Linux, OSX and Win. On Saturday 04 September 2004 05:26 pm, Justin French wrote: Can anyone suggest a PHP editor/IDE for OS X other than: - BBEdit (already using it) - Zend Studio (it's Java, not OS X native) What I'm hoping for is: - some form of auto-complete text for functions/constants/etc, - integrated testing/debugging - integration with local install of PHP - anything else that will make my life easier without 'getting in the way'. My guess is it doesn't exist, but it's worth a shot. PLEASE, no On Windows I use... or I just use 'Text Editor X' -- I'm looking for something more than a basic text editor, and it has to be OS X native (not some ugly, sluggish Java thing). *** with best regards *** Andrei Verovski (aka MacGuru) *** Mac, Linux, DTP, Programming Web Site *** *** http://snow.prohosting.com/guru4mac/ Hehe, i hope that you don't mind that i tag along here, but i'm also looking for a good IDE. I've installed Eclipse, but i can't really seem to understand exactly what i have to do in order to install phpEclipse. The installation help thing says that i have to install wampp first, but i have absolutely no idea what that is... What happened to the good old clean install.exe files?! Should i install that wampp thing? (i hope it's not some twisted virus :x) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [PHP5] paradox ? Bug ?
I think this basically sums up the problems of the current handling of existence-checking in overloaded objects: We have an object that has user-defined methods for getting and setting object properties (__get() and __set(), respectively). These methods get and set the properties in a private array (private: can only be access from within the object itself). Example (mostly stolen from php.net): ?php class Foo { // This array holds the properties private $elem = array(); // This method is automatically called when an // undefined (or inaccessible, as $array) property is // called. The name of the called property is the only // argument. public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { trigger_error(Oooops, E_USER_WARNING); } } // Same as before, but is called when setting a // property public function __set ($prop, $val) { $this-elem[$prop] = $val; } } // Instantiate the class $foo = new Foo(); // Check if $foo-bar ($foo-elem['bar']) is set if (isset($foo-bar)) { echo \$bar is set\n; } else { echo \$bar is not set\n; } // Set $foo-bar to 'foobar' $foo-bar = 'foobar'; // Print the value of $foo-bar echo $foo-bar, \n; // foobar // Check if $foo-bar ($foo-elem['bar']) is set if (isset($foo-bar)) { echo \$bar is set\n; } else { echo \$bar is not set\n; } ? Now, since we access the properties of $foo in a 'virtual' manner - meaning $foo-bar doesn't really exist, it's actually $foo-elem['bar'] (if it were public, that is) - we can assume that we can check for property existance in the same 'virtual' way, right? Wrong. If we could, the above would output this: $bar is not set foobar $bar is set Yet it returns: $bar is not set foobar $bar is not set If we want to check whether or not $bar exists in $foo, we have to add a method to the Foo class: public function isSet ($prop) { if (isset($this-elem[$prop])) { return TRUE; } else { return FALSE; } } Which is rather dumb, considering that the intention of isset() is to check whether or not a variable exists! So far there has been two suggestions as to what can be done: 1. Change isset so that it automatically detects overloaded properties 2. Let the user define a custom __isSet() method, similar to the one above, that is called each time a property of the class is checked with isset() Maybe there's some other angles/ideas/suggestions? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Statistics
I'm trying to develop a set of functions that can handle the statistics of a website. I want them to be as flexible as possible, and i want to be able to have several different views (day, week, month, year). For example if i wanted to know how many visitors, visits and page hits there was each month last year, i could call the function like this: $months = Statistics::getStats(STAT_VIEW_YEAR, 2004); foreach ($months as $month) { echo $month['visitors']; // ... } I'm thinking of doing it like this: ?php class Statistics { public static function logPageView () { global $db; // $db is just a MySQL object interface $ip = $_SERVER['REMOTE_ADDR']; $ex = STATS_SESSION_EXPIRE; $result = $db-query(UPDATE `statistics` SET `visit_end` = NOW() AND `hits` = `hits`+1 WHERE `ip` = '$ip' AND NOW()-`visit_end` $ex ORDER BY `visit_start` DESC LIMIT 1); if ($db-affectedRows() !== 1) { $db-query(INSERT INTO `statistics` (ip, visit_start, visit_end) VALUES ('$ip', NOW(), NOW())); } } public static function getStats ($view = STATS_VIEW_DAY, $date) { global $db; switch ($view) { case STATS_VIEW_YEAR: $sql = YEAR(visit_start) = $date GROUP BY MONTH(visit_start) ORDER BY MONTH(visit_start); break; // More cases default: return FALSE; } return $db-query(SELECT COUNT(DISTINCT ip) AS visitors, COUNT(*) AS visits, SUM(hits) AS hits FROM `statistics` WHERE . $sql)-fetchArray(); } } ? Is there a simpler way of approaching this? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Statistics
John Holmes wrote: From: Daniel Schierbeck [EMAIL PROTECTED] Is there a simpler way of approaching this? Use an already written program that parses your web logs and already gives you this information? ---John Holmes... I feel like doing it myself :) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Handling XML output in a slim way
Markus Fischer wrote: Hi, up until now, when outputing XML I've been constructing the output as a continous string-soup in such ways like [...] $xml .= printf('item name=%s%s/item', makeXmlSave($name), makexmlSave($contentOfItem)); [...] makeXmlSave() makes sure that quotes, ampersand, and are properly escaped with their entity reference. However I was thinking if it wasn't possible to e.g. generated a a complete DOM tree first and then just having this tree being dumped as XML. I'm using PHP4 right now. thanks, - Markus In PHP5 the simplexml functions make it very easy to read/edit XML documents. For instance friends.xml: friends friend nameCharlotte/name age21/age /friend friend nameDan/name age25/age /friend friend nameJennifer/name age19/age /friend /friends With simplexml you can load that XML document into an object: ?php $friends = simplexml_load_file('friends.xml'); foreach ($friends-friend as $friend) { echo Name: {$friend-name}; Age: {$friend-age}\n; } ? Which would output: Name: Charlotte; Age: 21 Name: Dan; Age: 25 Name: Jennifer; Age: 19 You can also edit the object and save it, either as an XML file or as an XML-formatted string. Search for 'simplexml' on php.net to see the full documentation. But it only works in PHP5 ;) -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP5]__get, __set and isset()
Frédéric hardy wrote: Is it possible to do something like this : class foo { private $array = array(); function __construct() { ... } function __get($key) { return (isset($this-array[$key]) == false ? null : $this-array[$key]); } function __set($key, $value) { $this-array[$key] = $value; } } $foo = new foo(); if (isset($foo-bar) == false) $foo-bar = 'bar'; else echo $foo-bar; It seems that isset($foo-bar) return ALWAYS false. Bug ? Fred. It seems that you are right. I've tried off this code: ?php class OO { private $elem = array(a = 1); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { return NULL; } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $o = new OO(); echo isset($o-a) ? yes\n : no\n; echo isset($o-b) ? yes\n : no\n; echo is_null($o-a) ? yes\n : no\n; echo is_null($o-b) ? yes\n : no\n; ? I expected something like this: yes no no yes But got this: no no no yes It looks like isset() can't handle object properties correctly. I'll post the bug on php.net. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP5]__get, __set and isset()
M. Sokolewicz wrote: next time, please read the isset documentation carefully. I quote: [quote]isset() will return FALSE if testing a variable that has been set to NULL.[/quote] Catalin Trifu wrote: Hi, Is this really a bug. I think not. There is no variable $o-a or $a-b in the class OO there is only the variable $elem and $a and $b is a member of that array So ... The fact that PHP5 provides __set and __get magic functions does not mean that the actual variables exist with that particular name in the class ? Perhaps it would be nice to have a __isset magic function ? Cheers Catalin ?php class OO { private $elem = array(a = 1); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { return NULL; } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $o = new OO(); echo isset($o-a) ? yes\n : no\n; echo isset($o-b) ? yes\n : no\n; echo is_null($o-a) ? yes\n : no\n; echo is_null($o-b) ? yes\n : no\n; ? I expected something like this: yes no no yes But got this: no no no yes It looks like isset() can't handle object properties correctly. I'll post the bug on php.net. -- Daniel Schierbeck Next time, please read my post carefully. $a is not NULL, it is 1. Therefore, isset($a) should return TRUE, which it does normally, just not when $a is returned via __get(). @catalin: Yes, a __isset() method would be ideal, but i still can't see why isset() shouldn't support the overloaded variables - after all, if you are able to access such a variable using the __get() method, why shouldn't you be able to check whether or not it has been set? Currently, if you want to check whether a variable in the $elem array is set, you would have to use this: $a = $o-a; echo isset($a) ? yes\n : no\n; Which in my opinion isn't optimal. Bottom line - if you can access a variable through property overloading you should be able to use isset() on them as well. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: [PHP5]__get, __set and isset()
Catalin Trifu wrote: Actually i think no property is created; not in the sense of real object property. The only real property of the object is $elem. The $o-a, and $o-b are, IMHO, not object properties; It is true that one can access $o-a and $o-b, but what is actually returned is a member of the array $elem, and only because of the implementation of the magic functions __set and __get. isset() does test for an actual variable beeing set, which is definetely not the case. I agree however that this is confusing. I am definetely puzzled by the usefullness of these methods since i consider this to be a real error trap; it would be so easy to fill up an object with values without knowing what they are and what they are supposed to do and when developing some kinda library, things can get really messy. On my part I would stick with the usual declaration of properties and not use __set() and __get(). I think it's much cleaner to say: class OO { /** this is variable a and means ... */ public $a; /** this is variable a and means ... */ public $b; } cheers, Catalin Frédéric hardy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Yes but not :-). With you use these magic functions, when you write $o-a = 'foo', you create a property in the object. Not ? Even if it is stored in an array member, __set() create a property and __get() retrieve its value. Doc says : The $name parameter used is the name of the variable that should be set or retrieved. The __set() method's $value parameter specifies the value that the object should set set the $name. Conclusion : class OO { private $elem = array(); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { return NULL; } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $o = new OO(); echo isset($o-a) ? yes\n : no\n; # Must return false and return false effectively, cool $o-a = 'foo'; echo isset($o-a) ? yes\n : no\n; # Must return false and return false effectively, NOT COOL Fred. Catalin Trifu wrote: Hi, Is this really a bug. I think not. There is no variable $o-a or $a-b in the class OO there is only the variable $elem and $a and $b is a member of that array So ... The fact that PHP5 provides __set and __get magic functions does not mean that the actual variables exist with that particular name in the class ? Perhaps it would be nice to have a __isset magic function ? Cheers Catalin ?php class OO { private $elem = array(a = 1); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { return NULL; } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $o = new OO(); echo isset($o-a) ? yes\n : no\n; echo isset($o-b) ? yes\n : no\n; echo is_null($o-a) ? yes\n : no\n; echo is_null($o-b) ? yes\n : no\n; ? I expected something like this: yes no no yes But got this: no no no yes It looks like isset() can't handle object properties correctly. I'll post the bug on php.net. -- Daniel Schierbeck -- === Frederic HARDYEmail: [EMAIL PROTECTED] HEXANET SARL URL: http://www.hexanet.fr/ ZAC Les CharmillesTel: +33 (0)3 26 79 30 05 3, allée Thierry Sabine Direct: +33 (0)3 26 61 77 84 BP 202 - 51686 REIMS CEDEX 2 FRANCE === I personally find the __get() and __set() methods very usefull, especially when constructing object hierarchies. But, as Frédéric said, they're not sufficient. Either make isset() work with the __get() method or add a __isset() magic method. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Storing image in database
Dre wrote: line 8 is ?php just that .. and the code before it is the following //== html head titleUntitled Document/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /head body //== Marek Kilimajer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dre wrote: Hi .. I'm trying to save and view image files in a MySQL database, I made the save operation successfully, I stored the image file name, type, size and the image file itself the problem occurred when I tried to retrieve the image data I've previously stored, in specific when I tried to preview the image file I tried to make something like the following but it did not work //== = ?php include(db.php); $sql = select * from members_data where mem_id = '4335'; $result = mysql_query($sql); if(mysql_num_rows($result)0) { $row = mysql_fetch_array($result); $image_type = $row['image_type']; $image = $row['personal_pic']; header(Content-type: $image); print $image; } //== = Everytime I try to execute this code I get this error Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\ELBA\admin\Untitled-1.php:8) in C:\Program Files\Apache Group\Apache2\htdocs\ELBA\admin\Untitled-1.php on line 18 If the script you posted is Untitled-1.php you did not post the whole script. You output something on line 8, possibly a white space. You cannot output anything before any header(), setcookie(), or session_start() function calls. And header(Content-type: $image); should be header(Content-type: $image_type); That's why the script fucks up. You cannot send any output to the browser prior to a header. Either send the header before you send the HTML or use output buffering, eg.: ?php ob_start() ? html head... ?php include '...'; // Blabla ? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object Overloading in PHP5
Frzzman wrote: Daniel Schierbeck wrote: Stefan wrote: It's a bug. * Siehe http://bugs.php.net/bug.php?id=28444 ... und ... * http://news.php.net/php.bugs/63652 A workaround is possible using __call( $name, $args) { return( $this-__get( $name)); }. But it sucks, since constructs using array indices are impossible as $obj-not_existing_attr()[0] regards Daniel Schierbeck wrote: Do you guys have any idea why this code: ?php class Foo { private $elem = array(); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { trigger_error(Property '$prop' not defined, E_USER_ERROR); } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $obj = new Foo; $obj-a = new Foo; $obj-a-b = Foobar; ? returns this: Fatal error: Cannot access undefined property for object with overloaded property access in ... on line 24 Where line 24 is: $obj-a-b = Foobar; ? %!#%%(/)((%%!#%%#!%#! Calm down, calm down... it's not good for your health :D Hehe, I'm allright now, I just needed a cold shower... -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Object Overloading in PHP5
Do you guys have any idea why this code: ?php class Foo { private $elem = array(); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { trigger_error(Property '$prop' not defined, E_USER_ERROR); } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $obj= new Foo; $obj-a = new Foo; $obj-a-b= Foobar; ? returns this: Fatal error: Cannot access undefined property for object with overloaded property access in ... on line 24 Where line 24 is: $obj-a-b= Foobar; ? -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object Overloading in PHP5
Stefan wrote: It's a bug. * Siehe http://bugs.php.net/bug.php?id=28444 ... und ... * http://news.php.net/php.bugs/63652 A workaround is possible using __call( $name, $args) { return( $this-__get( $name)); }. But it sucks, since constructs using array indices are impossible as $obj-not_existing_attr()[0] regards Daniel Schierbeck wrote: Do you guys have any idea why this code: ?php class Foo { private $elem = array(); public function __get ($prop) { if (isset($this-elem[$prop])) { return $this-elem[$prop]; } else { trigger_error(Property '$prop' not defined, E_USER_ERROR); } } public function __set ($prop, $val) { $this-elem[$prop] = $val; } } $obj = new Foo; $obj-a = new Foo; $obj-a-b = Foobar; ? returns this: Fatal error: Cannot access undefined property for object with overloaded property access in ... on line 24 Where line 24 is: $obj-a-b = Foobar; ? %!#¤%¤%(/)((%¤%!#¤%%#!%#!¤ -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: exploding
M. Sokolewicz wrote: Jake McHenry wrote: Hi everyone. Is there a way to explode by every character in the variable? Example: $var = 8; $test = explode(, $var); output would be $test[0] = 0; $test[1] = 0; $test[2] = 0; $test[3] = 0; $test[4] = 8; Can I get an array like that? Thanks, Jake McHenry MIS Coordinator Nittany Travel http://www.nittanytravel.com 570.748.6611 x108 well, you can access strings like arrays already. So instead of exploding you can already do something like $var = 15 is a number; $var[2] = 7; echo $var; // will output: 17 is a number same way goes for accessing them In PHP5, the square brackets have been replaced with the curly ones (the square brackets still works, but it's deprecated) $string = 12345; echo $string{2}; // 3 -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] system command
Ron Clark wrote: Capture the output in the $output variable then ob_clean to empty the output buffer before printing the the desired message. ob_get_clean() is preferable: $output = ob_get_clean(); // Gets the buffered output and cleans the buffer -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to count objects instances
Robert Cummings wrote: On Mon, 2004-08-23 at 20:54, John Holmes wrote: [EMAIL PROTECTED] wrote: hi, What is best method(if it's possible) to count how many times an object is instanced in one time script call? I means that if i have a class named Test, i what to know how many times she's called, how many copies exists etc. The idea is for monitoring in the way to optimizing the code. The method get_declared_classes() only shows only the classes included/required. There's no predefined variable or method for determining this, that I'm aware of, short of counting how many new Test lines you have. You could write a wrapper class for Test that kept count of the instances and returned a new object upon request... In PHP5: ?php class Foo { static $instances = 0; function __construct() { Foo::$instances++; } function __destruct() { Foo::$instances--; } static function getNumInstances() { return Foo::$instances; } } $foo = new Foo(); $fee = new Foo(); echo 'Count: '.Foo::getNumInstances().\n; unset( $foo ); echo 'Count: '.Foo::getNumInstances().\n; Add this to the class as well: public function __clone () { self::$instances++; // You might as well use the self operator } -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Crazy Serialize/Header/$_POST PHP Error - Is this a bug?
Eric Peters wrote: I think I've boiled my problemfor some reason I can't header() a serialized $_POST variable Running PHP 5.0 Final (and also tested with 4.3.3): -- begin file -- ?php function jpcache_debug2($s) { header(X-CacheDebug-five: $s); print $s; } $myVariable = serialize($_POST); jpcache_debug2($myVariable); ? html body form method=POST action=test-error.php input type=hidden name=foo value=bar input type=submit value=blah /form /body /html -- end file -- Response Headers - Begin output: Date: Mon, 23 Aug 2004 23:56:14 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) PHP/5.0.0 mod_ssl/2.8.12 OpenSSL/0.9.6b X-Powered-By: PHP/5.0.0 X-CacheDebug-five: a:0:{} Connection: close Transfer-Encoding: chunked Content-Type: text/html a:1:{s:3:foo;s:3:bar;} html body form method=POST action=test-error.php input type=hidden name=foo value=bar input type=submit value=blah /form /body /html Anyone know why my header() output behaves so funky? Thanks, Eric Try to use unserialize(); -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to count objects instances
Curt Zirzow wrote: * Thus wrote Robert Cummings: On Mon, 2004-08-23 at 20:54, John Holmes wrote: [EMAIL PROTECTED] wrote: You could write a wrapper class for Test that kept count of the instances and returned a new object upon request... In PHP5: ?php class Foo { static $instances = 0; function __construct() { Foo::$instances++; } function __destruct() { Foo::$instances--; } And: function __clone() { Foo::$instances++; } Curt Ooops, didn't see your post, hehe... By the way, use self instead of Foo, just in case you change the class' name. -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] system command
Ron Clark wrote: Daniel Schierbeck wrote: Ron Clark wrote: Capture the output in the $output variable then ob_clean to empty the output buffer before printing the the desired message. ob_get_clean() is preferable: $output = ob_get_clean(); // Gets the buffered output and cleans the buffer Didn't need the contents of the buffer. All I needed was the last line which was contained in $output = system(). Sorry, my bad... -- Daniel Schierbeck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class Con- and Destructor Inheritance
Curt Zirzow wrote: * Thus wrote Justin Patrin: On Sun, 22 Aug 2004 13:04:11 +0200, Daniel Schierbeck [EMAIL PROTECTED] wrote: ... Note: Parent constructors are not called implicitly. In order to run a parent constructor, a call to parent::__construct() is required. Is this an error in the manual or in PHP itself? Should I report it somewhere? No, this is not a bug. This means that if you define a new constructor / destructor, the parent class's won't be called unless you put it in the new ones. Although not a bug, it is a little misleading, i've corrected it to explain when the constructor isn't called. Curt Thanks, all i needed to know :) The manual's a bit confusing on that part... Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Cookie behaviour
Michael Purdy wrote: Folks I am running php 5.0.1 on NT. I have a small test script as shown below script language=php setcookie('cat','large',time()+3600); setcookie('dog','small',time()+3600); /script The outcome of this script is that only the LAST cookie is successfully stored.despite having a different name. Is this because they are both being set from within the same script and therefore conflicting with each other? Mike First of all, use ?php and ? instead of script language=php and /script, the latter is not always supported. Second, are you sure that you don't output any non-header information to the browser before setting the cookies? Try using output buffering: ?php /* start output buffering */ ob_start(); /* print out something stupid (it is saved to the buffer) */ echo mooo\n; /* set them cookies */ setcookie(foo, bar); setcookie(bar, foo); /* it's getting even stupider (can you even say that?!) */ echo baaah\n; /* print the buffered output and end the output buffering */ ob_flush(); ? Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I open Save As Dialog Box?
Php Junkie wrote: Ave, I'm facing a little problem. I have created a File Manager Application for my company which has a place where authorized users can download the stored files. The files are of various MIME Types.. Mainly PDF, TXT DOC. What I want to do is basically... When the user clicks on the Download Button... The Save As Dialog Box should appear... What is happening right now is that the file opens in it's related software (Word, Acrobat, Notepad etcetera). I don't want the file to open in it's native software. I know I need to use the header (Content-type: application/octet-stream); But I don't know how. Can anyone help? Thanks. Try using header(Content-type: application/force-download) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Class Con- and Destructor Inheritance
Hello there. I was experimenting a bit with the constructors and destructors, and found that this code: ?php class First { public function __construct () { echo Hello, World!\n; } public function __destruct () { echo Goodbye, World!\n; } } class Second extends First { } $second = new Second; ? Outputs Hello, World! Goodbye, World! , yet the PHP manual (http://www.php.net/manual/en/language.oop5.decon.php) says: Note: Parent constructors are not called implicitly. In order to run a parent constructor, a call to parent::__construct() is required. Is this an error in the manual or in PHP itself? Should I report it somewhere? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: OO in PHP5.0 - Referencing Object or not?!
Raffael Wannenmacher wrote: hello together look at the following code ... why is this .. -- code start if ( is_object($this-getManagerObject()-getDataFieldManager()) ) { for ( $j = 0; $j $this-getManagerObject()-getDataFieldManager()-getCount(); $j++ ) { if ( $this-getManagerObject()-getDataFieldManager()-m_objData[$j]['GI_ID'] == $this-getID() ) { $l_objDataField = new GalleryDataField( $this-getManagerObject()-getDataFieldManager(), $this-getManagerObject()-getDataFieldManager()-m_objData[$j] ); $l_objDataField-generateXML(); $l_strData .= $l_objDataField-getXML(); unset($l_objDataField); } } } -- code end .. about 2 seconds slower than this .. -- code start $l_objDataFieldManager = $this-getManagerObject()-getDataFieldManager(); if ( is_object( $l_objDataFieldManager ) ) { for ( $j = 0; $j $l_objDataFieldManager-getCount(); $j++ ) { if ( $l_objDataFieldManager-m_objData[$j]['GI_ID'] == $this-getID() ) { $l_objDataField = new GalleryDataField( $l_objDataFieldManager, $l_objDataFieldManager-m_objData[$j] ); $l_objDataField-generateXML(); $l_strData .= $l_objDataField-getXML(); unset($l_objDataField); } } } unset($l_objDataFieldManager); -- code end ??? i just read, that objects in php 5 automatically returned as reference? in my code it doesn't seems like that!! ps: variable m_objData contains a lot of data from a mysql db thanks for answers. As you can read in some of the posts here, it only SEEMS like the objects are passed by reference (it's a conspiracy!). I'm not sure if it'll help you, but try using the ampersand () symbol to force passing-by-reference. Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Text from file into database
Phpu wrote: Hi, I have a file, test.txt. The containig of this file is: line 1 line 2 line 3 -- and so on I want to create a script that will read each line of the file and insert it to database. I am new to php and maybe you could help me Thanks I depends on what kind of database you wish to use (you probably have MySQL, though PostgreSQL would be preferable). If you have a large amount of lines I recommend you use prepared statements. But first of all, tell us which database you're going to use. Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: OO in PHP5.0 - Referencing Object or not?!
L0t3k wrote: Raffael, object in PHP5 _are_ passed by reference. internally, objects are handles unique to a request, so all youre doing is passing a handle around. note, however, that simple variable access will _always_ be faster than method calls. this is true in C as well as PHP, except in PHP the effects are more noticeable since it is interpreted rather than compiled. l0t3k Just to get things straight: ?php class Foo { public $foo = bar; } $obj1 = new Foo; $obj2 = $obj1; $obj3 = $obj2; $obj2 = NULL; echo $obj1-foo; ? outputs bar while ?php class Foo { public $foo = bar; } $obj1 = new Foo; $obj2 = $obj1; $obj3 = $obj2; $obj2 = NULL; echo $obj1-foo; ? outputs Notice: Trying to get property of non-object in /free1go/a/o/www.aoide.1go.dk/lab/bar.php5 on line 16 Hence, there is a difference between references and object handles. When you pass by reference,for instance $foo = $bar, where $bar is an object, $foo will point to whatever $bar is pointing to. When you write $foo = $bar, $foo will point to the same object as $bar, but $foo is not forever bound to $bar, as in the first example. It simply has the same object handle. Therefore, when you delete $bar ($bar = NULL), $foo will be intact when using =, but will be set to NULL as well when using =. Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get reference count on a variable.
Robert Cummings wrote: In PHP5 to get a copy of, versus a reference to, an object the developer must call the __clone() method for the target object: $obj = new Foo(); $copyNotReference = $obj-__clone(); The correct syntax for that is: $obj = new Foo; $copyNotReference = clone $obj; Cheers, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Get reference count on a variable.
Robert Cummings wrote: On Sat, 2004-08-21 at 14:38, Daniel Schierbeck wrote: Robert Cummings wrote: In PHP5 to get a copy of, versus a reference to, an object the developer must call the __clone() method for the target object: $obj = new Foo(); $copyNotReference = $obj-__clone(); The correct syntax for that is: $obj = new Foo; $copyNotReference = clone $obj; Ahh cool. I guess I was reading an old document. Perhaps from before a keyword was added for better code clarity :) Cheers, Rob. Hehe, no problem mate. By the way, does anyone know what happened to the delete keyword? I saw it in a Zend article before the final release of PHP 5, but i can't find it anywhere. Ooops, off-topic, soory ;) Best regards, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Overloaded Class The __tostring() Method
I am trying to build an XML-formatted string from an object. I use this code: ?php class XML_Object { private $childs = array(); public function __get ($prop) { if (isset($this-childs[$prop])) { return $this-childs[$prop]; } else { trigger_error(Property '$prop' not defined., E_USER_WARNING); } } public function __set ($prop, $val) { $this-childs[$prop] = $val; } public function __tostring () { $re = ; foreach ($this-childs as $key = $val) { $re .= $key$val/$key; } return $re; } } $error = new XML_Object; $error-no = 2; $error-str = Blablabla; $error-file = a_file.php; $error-line = 54; $xml = new XML_Object; $xml-error = $error; echo $xml; ? But i only get this response: errorObject id #1/error Can someone help me? I want to print the contents of the $error object as well... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php