Re: [PHP] Good way to organize code using classes???
On Tue, 28 Jan 2003 16:20:20 +0100, Maxim Maletsky wrote: I use PHP classes extensively and very often use classes within other classes. First off, I would make sure to take advantage of inheritence as much as possible. I have heirarchies up to 4 deep for some of my classes depending on how much specialization I need while at the same time maintaining only one set of code for functionality common to all subclasses. As for using classes within classes, I don't include the classes within a class definition nor within a method def. I include the class def in the class file but outside the actual class {} statement. When I instantiate the class, if I will need the object ref to pass to other classes or to other methods within the calling class, I assign the initial object instantiation to a class variable. That way any class methods can have ready access to that class via the ojbect reference stored in the class variable. Only when I know for sure that the use of a class will be for one purpose do I include and instantiate within a method. as always, YMMV depending on the structure of your project. NOTE: There is a set of new PHP functions that allow a sort of dynamic multiple inheritence. You can look here for info: http://www.php.net/manual/en/ref.objaggregation.php Jeff @ Nilaab [EMAIL PROTECTED] wrote... : Hello everyone, I want to be able to use objects to create my future pages. My goal is to use methods of classes to make the original front-line script easier to read, while all the processing is done with a simple call to the different classes from a single class. Please read futher, as I'll get to a point and to my question... I have many classes that do different tasks, like formValidator.class, stringManipulator.class, db.class, fileManipulation.class, template.class, etc (these are self-explanitory as their names suggest). Then, I might have a class called category.class that adds, deletes, edits, moves, and renames categories within the filesystem and database. But I would have a front-line script called category.php that would call the necessary methods of category.class at certain points, depending on the task being done on a specific step. In other words I want category.class to call the other classes and do something with them, then in turn I want category.php to call objects in category.class for a specific task, such as: ?php // category.php include (category.class); $cat = new category (); $cat-addCategory($new_cat_name); // or $cat-editCategory($cat_name); // or $cat-deleteCategory($cat_name); // or $cat-moveCategory($cat_name); // or $cat-renameCategory($cat_name); ? My question is: How can I call a class within another class and do something with it? Right now I'm doing it the most convenient way I know, which is including other classes using the include() function within the methods of the category.class. There is no multiple-inheritance allowed in PHP, so I can only use inheritance on one class. Including new classes within the existing classes is not such a bad idea as it ensures you to have only the necessary classes called. I am also extremely skeptical about creating too many classes at a time in one script. Do the above examples degrade performance speed of the script when I call too many classes? Also, isn't there a way to use sessions to save created classes and then use them again for other scripts without the need to make a new instance of the same class again and again? yes, you can serialize/unserialize classes into the sessions. This makes it a little more complicated, but can be helpful sometimes. I am really looking for a better way to organize my code while still being able to use these classes whenever I need them and at the same time keeping the category.php file clean and easy to read. Is there a tutorial on how to organize code? I'm not looking for html template tutorials. Just how to get around inheritance limits while still keeping performance and clean-code in mind. You know what I have once done? I created a file with functions that return you the object pointers. It would create (declare) the class whenever it was not declared before or just return the pointer from a global variable if it was declared before. That way, you only load a few functions, and whenever you need a class you assign a variable to the function's return to have the class. This limits you script to only classes you use and no includes within the script itself. A kind of silly method, but can be easy to work with. Also, check out the new Zend 2 engine, it has tons of improvements with classes for PHP5. Currently the code is in CVS (checkout php5 module). Changes are listed here: http://cvs.php.net/co.php/ZendEngine2/ZEND_CHANGES -- Maxim Maletsky [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
Re: [PHP] Get command line output
On Thu, 23 Jan 2003 00:14:07 +0800, Jason Wong wrote: either use PHP to parse out the entirety of the output or make your command pipe its output to other commands such as sed awk before it gets to PHP. w | tail +3 | awk '{print $1,$3,$5}' Jeff On Thursday 23 January 2003 00:10, Greg Chagnon wrote: Does anyone know how to get certain parts of the output from an exec of a certain command? For example...if I run w I get this output: [root@Lunar]:~ w 11:02am up 56 days, 17:39, 1 user, load average: 0.07, 0.02, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0brpt-sh6-port214 11:01am 0.00s 0.27s 0.06s w Now what if I just want the infor on the 3rd line, and info about anyone else who is logged in, such as the username, the host, and the time without getting all the uptime and the header info? Thanks! exec() 'returns' the output of the command in an array. Just extract from the array whatever line(s) you need. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Good XML/XSLT mailing list?
On Wed, 22 Jan 2003 10:21:36 -0600, Chris Boget wrote: This is a good QA site: http://www.dpawson.co.uk/xsl/sect2/sect21.html and XSLT-list here: http://www.dpawson.co.uk/xsl/list.html Jeff Sorry for the OT post but I know many of you use the above. I subscribed the the PHP-XML mailing list but alas, haven't seen activity on it since the middle of last year. Could you guys recommend a good (quality over quantity) XML/XSLT mailing list? If it's a list geared more towards newbies, all the better but that wouldn't be a requirement. Thanks for any assistance you can provide. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] accessing data from classes
In [EMAIL PROTECTED], Samuel Ottenhoff wrote: It is good that you are looking into classes and functions. The concept you are missing is that of returning a result. At the end of your function mysql_query, add a line: return $result; Then, when you call that function, make it like this: $resultArray = $TemplateTable-mysql_query(select ); Now you can pass $resultArray on to a different function. Sam Alternatively, you can define a class variable where you will be storing the query results and then access that variable from outside. so, class foo { var $results; function bar($query) { while { $this-results[] = $row; } } } Then, from outside the class, you can access the variable. $bar = new foo(); $bar-bar(select foo...); print($bar-results); etc... Jeff On 3/12/02 3:48 PM, caspar kennerdale [EMAIL PROTECTED] wrote: I am just getting my head around classes, so forgive me if this is a schoolboy error! In order to learn I am re-writing my content management system and am in the process of writing an HTML.class and a MYSQL.class. so far so good. I spawn new instances of a table for example, sending parameter,and a table is output. now in my MYSQL.class- I want to send a query to my class which then returns an array- my database row or rows. the problem is that whilst my array is created- I only seem to be able to manipulate it within my MYSQL class. This is not satisfactory as I really want to be able to send it on to my HTML.class for formatting etc. I obvioulsy do not want to format any 'echoed' output from within my databasee class. Here is a bit of sample code- Once my database is open I call my query like this- $TemplateTable = new DB; $TemplateTable-mysql_query('SELECT * FROM template ORDER BY name ASC LIMIT 10'); This is the function within my MYSQL.class function mysql_query($query){ $a= 0; while($row=mysql_fetch_row($SQL)) { $new_row = join('***',$row); $result[] = $new_row; echo $result[$a].br; $a++; } } So here I am creating a string with each row in my database which is delimted by *** - $new_row.and am placing each row in anew array called $result. I can evaluate and format either $new_row or $result from within mysql_query() but I really want to do is to send it on to another funtion or even better another class- or access the values glabbally as variables. Any ideas or am I missing something really obvious? Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: DOM XML?
In [EMAIL PROTECTED], Yasuo Ohgaki wrote: Daniele Baroncelli wrote: Hello, I would like to restyle one big site in XML and I would like some brief straight info/suggestions. I am definitely interested in DOM XML, but as far as I can understand, the module is still experimental and there to main risks: - The module is not completely stable - The functions are likely to change Are you able to confirm me these? I would agree that the DMO stuff isn't 100% stable but it is already functional enough to be usable. I have been using the DOM stuff in a production enviornment including the XPath functionality for a good four or five months now without major problems. The XSLT functionality is coming along nicely as well. I would suggest at least playing around with it to see if it fits your needs. I think you will find advantages to using it over the saxon-style stuff in the other XML PHP functions, especially if you utilize the XPath search functionality. Jeff You are right about this. But please use it and report bugs if you find one. The more users, it will be more stable quickly. Please also try latest snapshot for experimental modules/functions. http://snaps.php.net/ As an alternative, it seems the only safe way to develop XML in PHP is by using the Expat module. Is this your view too? I would say yes, but you may experience problem(s). In any case, are you able to indicate some good web references for XML in PHP ? I don't know this one ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: How do I do this
In [EMAIL PROTECTED], Chris Boget wrote: Either of these should work: $str = preg_replace(/(\[[A-Z]+\])/,br\\1,$str); $str = ereg_replace((\[[A-Z]+\]),br\\1,$str); e.g.: ?php $str = [hi] there, this is me [HI] there, this is me; print($str); $str = preg_replace(/(\[[A-Z]+\])/,br\\1,$str); //$str = ereg_replace((\[[A-Z]+\]),br\\1,$str); print($str); ? Jeff Warrington I've got the following possible (example) strings: [hi] there, this is me [HI] there, this is me [ho] there, that is you [HO] there, that is you [hey] there, where are you [HEY] there, where are you and so on. I'm trying to come up with a regex that will find the capitalized text (only) between the square brackets, including the brackets (ie, the [HI], [HO], [HEY]) and basically put a br right before. So, after the regex/replace, it'll look like this: [hi] there, this is me br[HI] there, this is me [ho] there, that is you br[HO] there, that is you [hey] there, where are you br[HEY] there, where are you Now, the text between the brackets will be unknown, so I can't just do an instr() or strstr(). Any suggestions? Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: PHP/XSLT questions
In [EMAIL PROTECTED], Vikram Vaswani wrote: There is an undocumented function in php4.0.6 that allows you to specify an XSLT callback function for errors. You can then create a function to parse out the error array created by the callback function. It actually captures not only errors but also acts to log the work of the underlying XSLT processor. the function is xsl_set_error_handler and has parameters of 1) the XSLT processor instance and 2) A string representing the callback function name. e.g. xslt_set_error_handler($this-xslth,XSLT_ErrorHandler); Here is a sample of the callback function i have. Using the base php fuction error_log, you get the logging you want as well. function XSLT_ErrorHandler($parser, $code, $level, $errors) { if ($errors[msgtype] == log) { error_log(getNiceTime().XSLT Status Code: $code\n,3,XSLT_LOG); error_log(getNiceTime().XSLT Status Level: $level\n,3,XSLT_LOG); error_log(getNiceTime().XSLT Status: {$errors['msg']}\n,3,XSLT_LOG); } else if ($errors[msgtype] == error) { error_log(getNiceTime().XSLT Error Code: $code\n,3,XSLT_ERROR_LOG); error_log(getNiceTime().XSLT Error Level: $level\n,3,XSLT_ERROR_LOG); error_log(getNiceTime().XSLT Error FILE: {$errors['URI']}\n,3,XSLT_ERROR_LOG); error_log(getNiceTime().XSLT Error LINE: {$errors['line']}\n,3,XSLT_ERROR_LOG); error_log(getNiceTime().XSLT Error: {$errors['msg']}\n,3,XSLT_ERROR_LOG); } } Jeff Hi all, I am working with the XSLT functions in PHP 4.0.6. I'm trying to trap errors with the xslt_error() functions - however, the function generates no output even if I deliberately introduce errors into the XSLT sheet. Same goes for the openlog() function. Anyone have any ideas how I can use these to generate and log errors? TIA, Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] session help (session.gc_probability)
Hi, i am using sessions for a web application and was wondering whether it's possible to set the gc_probablity to 1%. I tried with a value of 0.25 but it appears that the gc callback function still runs at 1%. I figure that the value is an integer and rounds up the values but if someone can tell me different.. thanks, jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Newbie Question
In article 9c1gqf$i3j$[EMAIL PROTECTED], Wade [EMAIL PROTECTED] wrote: well, in your first IF clause, you refer to my_type without the $. For the else clause, you are outputting HTML while still inside the PHP block. try one of these: } else { ? select tabindex=13 name=my_type option value=0 selectedSelect a Value/option option value=oneOne/option option value=twoTwo/option option value=threeThree/option /select ?php } or } else { printEOF select tabindex=13 name=my_type option value=0 selectedSelect a Value/option option value=oneOne/option option value=twoTwo/option option value=threeThree/option /select EOF; } hope that helps, Jeff I wanted to say thanks to all those that have helped me. This is really a great language and I am doing things I never thought I'd be able to do! Now to my question: I am doing some form validation, where I check the values entered by the user. If the value is correct, I format the results and print it out. If it is not correct, I want to allow them to fix it. When I have a text field, like first_name, I'm ok. But when I do an HTML list menu, I'm having troubles. Basically, this is what I want to do. If the value is correct, print the value. If it is not correct, display the list box. Here's an example (but you can see my else statement is wrong, and this is what I need help with): if (my_type != 0){ switch($my_type){ case one: print img src=\/trillion/img/one.gif\ width=\41\ height=\26\ alt=\One\; print One; break; case two: print img src=\/trillion/img/two.gif\ width=\41\ height=\26\ alt=\Two\; print Two; break; case three: print img src=\/trillion/img/three.gif\ width=\40\ height=\26\ alt=\Three\; print Three; break; } } else { select tabindex=13 name=my_type option value=0 selectedSelect a Value/option option value=oneOne/option option value=twoTwo/option option value=threeThree/option /select } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] session problems
hello all. I am attempting to register two session variables that are in fact class instances. As per instructions, the definitions for these classes are prepended to the files being loaded so the class defs are present when the session starts. If I do this on the first page: session_start(); session_register("off"); session_register("req"); where "off" and "req" are actually class instances and then try this on page two: header("Content-Type: text/plain"); (session_is_registered("req")) ? print("req: yes\n") : print("req: no\n"); (session_is_registered("off")) ? print("off: yes\n") : print("off: no\n"); var_dump($req); var_dump($off); I get a response that both $off and $req are registered variables. however the output of var_dump for $req is null while the output for $off shows the frozen object. If I reverse the order of the session_register on page one, then the var_dump shows values for $req but not $off. I am using DB storage for the sessions. my callback functions are operating - I can see the serialized data in the table for both the $req and the $off class instances. Any clues on where I need to look to solve this one? thanks, Jeff Running Apache 1.3.17 w/ PHP4.0.4pl1 './configure' '--with-apache=../apache_1.3.17' '--enable-track-vars' '--with-xml' '--with-dom' '--with-ibm-db2=/usr/IBMdb2/V6.1/' '--with-zlib' '--with-curl' '--with-pspell' '--with-mcrypt' '--with-sablot' '--enable-sablot-errors-descriptive' '--enable-inline-optimization' '--enable-trans-sid' '--with-config-file-path=/opt/gr/oas/lib/' session data in php.ini is: [Session] session.save_handler = user session.save_path = SESSION session.use_cookies = 1 session.name = XX (removed) session.auto_start= 0 session.cookie_lifetime = 0 session.cookie_path = / session.cookie_domain = .xxx.com (removed) session.serialize_handler = php session.gc_probability= 1 session.gc_maxlifetime= 600 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] session problems
In article 99u746$gra$[EMAIL PROTECTED], "Jeff Warrington" [EMAIL PROTECTED] wrote: Never mind everybody. It turns out that I had to set the odbc_longreadline setting to make sure that the full serialized session data was read from the DB. Jeff hello all. I am attempting to register two session variables that are in fact class instances. As per instructions, the definitions for these classes are prepended to the files being loaded so the class defs are present when the session starts. If I do this on the first page: session_start(); session_register("off"); session_register("req"); where "off" and "req" are actually class instances and then try this on page two: header("Content-Type: text/plain"); (session_is_registered("req")) ? print("req: yes\n") : print("req: no\n"); (session_is_registered("off")) ? print("off: yes\n") : print("off: no\n"); var_dump($req); var_dump($off); I get a response that both $off and $req are registered variables. however the output of var_dump for $req is null while the output for $off shows the frozen object. If I reverse the order of the session_register on page one, then the var_dump shows values for $req but not $off. I am using DB storage for the sessions. my callback functions are operating - I can see the serialized data in the table for both the $req and the $off class instances. Any clues on where I need to look to solve this one? thanks, Jeff Running Apache 1.3.17 w/ PHP4.0.4pl1 './configure' '--with-apache=../apache_1.3.17' '--enable-track-vars' '--with-xml' '--with-dom' '--with-ibm-db2=/usr/IBMdb2/V6.1/' '--with-zlib' '--with-curl' '--with-pspell' '--with-mcrypt' '--with-sablot' '--enable-sablot-errors-descriptive' '--enable-inline-optimization' '--enable-trans-sid' '--with-config-file-path=/opt/gr/oas/lib/' session data in php.ini is: [Session] session.save_handler = user session.save_path = SESSION session.use_cookies = 1 session.name = XX (removed) session.auto_start= 0 session.cookie_lifetime = 0 session.cookie_path = / session.cookie_domain = .xxx.com (removed) session.serialize_handler = php session.gc_probability= 1 session.gc_maxlifetime= 600 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ereg problem
In article [EMAIL PROTECTED], "Janet Valade" [EMAIL PROTECTED] wrote: if you include a hyphen in a character class, it must be the last entry in the range, otherwise it is interepreted as the range separator. [0-9+.\()-] is what you want (probably have to escape some of the chars above). Jeff I am using the following statement to check phone numbers. if (!ereg("^[0-9\-\+\.\ \)\(]{10,}$",$value)) { Can anyone tell me why this works for every character except the -. It doesn't see the hyphen as a valid part of the phone number, even though it recognizes the other characters, e.g. + or . Janet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] OOP in web development
In article [EMAIL PROTECTED], "Joe Sheble (Wizaerd)" [EMAIL PROTECTED] wrote: depending on the nature of what you are doing, one of the things that i like about using classes is the ability to group functionality under a larger structure, the class. Instead of having a series of disconnected functions, i can instead write them as class methods. another feature that is a basic feature of oop stuff is the idea of inheritence. So you can have a base class (CAR) that defines behaviour common to all instanaces of that class (var wheels, var door, method car start, method car turn signal on, etc...) Then you can subclass the CAR class to define specific behaviour for a particular car model (SPORTSCAR - var turbo, method car turbo on, etc..). again, depending on what you are doing, this can be very beneficial. I suggest you start small and also take a look at other people's code. You will find alot of classes out there that make alot of sense and can give you ideas of new ways of doing things Jeff I've been using PHP for over a year now and have been successfully running three different websites developed with PHP, but I've never done anything with classes or objects. Even when returning data from a mySQL database, I use mysql_fetch_array() instead of mysql_fetch_object(). What am I missing by not using objects and classes, other than reusability? What are the real benefits to using OOPs in PHP? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] regex with non-ascii characters
In article 059301c08981$7859a020$[EMAIL PROTECTED], "Remco Chang" [EMAIL PROTECTED] wrote: You need to find the ASCII codes for these characters and include them in the range of acceptable chars in the ereg. something like: [\xc0-\xff] where this represents a range of ASCII codes in octal Jeff hi, just a quick question... i can't seem to have ereg() work with non-ascii characters such as the character 'ö'. is this something that i can work around? remco chang www.bountyquest.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ereg_replace all items in a array
In article [EMAIL PROTECTED], "Joseph H Blythe" [EMAIL PROTECTED] wrote: What is happening is that you are replacing the variable $replaced on each iteration of the while loop. As a result, $replaced is only storing the most recent match. To see this, try this out: $keywords = "foo"; $data = "This is a lower foo. This is an upper FOO. This is a ucase Foo"; $lower = strtolower($keywords); $upper = strtoupper($keywords); $ucase = ucwords($keywords); $words = array($lower, $upper, $ucase); while ( list($key, $val) = each($words) ) { print("key: $key = val: $valbr"); $hilite = "font color=\"#ff\"" . $val . "/font"; $replaced[] = ereg_replace($val, $hilite, $data); } for($i=0;$isizeof($replaced);$i++) { echo $replaced[$i]."br"; } The first print statement will show you what keywords we are focusing on. The ereg_replace in this case is appending an arrary. If you then walk that array, you will see that each of your keywords was matched and highlited. that should get you a little further along. Jeff G'day PHP'ers I am trying highlight the results from a search, so far I have this working but only if the string is an exact match ie: case sensitive, for example: ?php $keywords = "foo"; $data = "This is a lower foo. This is an upper FOO. This is a ucase Foo"; $lower = strtolower($keywords); $upper = strtoupper($keywords); $ucase = ucwords($keywords); $words = array($lower, $upper, $ucase); while ( list($key, $val) = each($words) ) { $hilite = "font color=\"#ff\"" . $val . "/font"; $replaced = ereg_replace($val, $hilite, $data); } echo $replaced; ? Now as metioned this seems to work only for "foo" does anyone have any idea why? Also I need to be able to support mutiple keywords ie: foo Foo FOO, so basically I know I could split(" ", $keywords) then some how traverse the array making a new array of all possible case combinations then in my while loop replace each occurance found in $data with the highlighted replacment, sounds easy hmm If anyone has any ideas or can see what I am doing wrong so far, it would be mutch appreciated. Regards, Joseph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] expressions
In article 94t6hv$903$[EMAIL PROTECTED], "Kumanan" [EMAIL PROTECTED] wrote: if (eregi("[^0-9]{3}",$co_area)) { print("area code must be digits"); } or if (eregi("[^[:digit:]]{3}",$co_area)) if you use the POSIX regex fields. hi, im trying to fix this couple of hours but i couldnt find the mistake... can somebody look at it... first i want to check the $co_area for 3 digital ... it must contain 3 digital if ($co_area != !ereg("([0-9]{3})",$co_area)) { echo " * Area code must be 3 digital"; } second... nickname check works but the first letter could be any number or any letters with this code it accept only letters as first character... i just want any letter or numbers or - _ symboles from 3 to 12 characters... if ($nickname != !eregi("^[-\._\.0-9a-zA-Z]{3,12}$",$nickname)) { $error ="Nickname must be Alphanumeric[ a-z 0-9; - _ ; 3 - 12 characters ]"; $flak=1; } First mistake when using character classes in the pattern is that the hyphen must be at the end if it is to be included. Otherwise the hyphen is seen to be part of the range (0-9 or A-Z): so, ^[0-9a-zA-Z._-]{3,12} instead of what you have. You also should not need the trailing $. As in the first example, don't use the 'double negative' approach. use: if (eregi("^[^0-9a-zA-z._-]{3,12}",$nickname)) { echo "only alphanumeric buddy!"; } I didn't test this but it should be closer to success. Jeff i hope someone can help me to fix this... thanx kumanan [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation :ereg ()
In article [EMAIL PROTECTED], "kaab kaoutar" [EMAIL PROTECTED] wrote: If you wish to include a hyphen in the allowed character list of a pattern match, you must include it as the last character. So what you want should be more like: if (eregi("[^a-zA-Zëàéêêàäïüöûâç-]",$name)) { print("your name can't include non-letter, etc"); } You can add space with: [:space:] within the charachter class ([^a-zA-Z[:space:]ëàéêêàäïüöûâç-]) Jeff Hi again! I still did not fix my prob : I want to check, in a form, that the name input may include an alphabetical letter a- z, A-Z, or a space, or -, or à, or ä or ü etc how can i do that ? i used ereg("([a-z,A-Z][ë,à]?)",$name) then (!ereg("([a-z,A-Z,é,ê,è,ë,-,\t,à,ä,ï,ü,ö,û,â,ç])", $name)) i get the following warnin :REG_ERANGE:,invalid character range by the way how to add space " " and "-" ? Please help! Thanks _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] regular expression help
In article 005801c08668$e0459070$0201010a@shaggy, "Jamie Burns" [EMAIL PROTECTED] wrote: I tried something like this and your examples worked: $str = "tag element = \"value\" nextelement"; if (eregi("=[[:space:]]*\"([^\"]+)|=[[:space:]]*([[:alnum:]]+)",$str,$regs)) { print("yes - ".$regs[1].":".$regs[2]."br\n"); } since the pattern has an 'or' (|), you have to look in either the second or the third element of the array you use to store values from the ereg. Jeff can anyone help me figure out a regular expression to find the value of a tag element? for example: tag element="my value" tag element=value tag element="my value" nextelement tag element=value nextelement tag element = "my value" tag element = value tag element = "my value" nextelement tag element = value nextelement so in each of the above i need to find either "my value" or "value"... i tried this but it wont work for every situation: ereg("element[ ]*[=][ ]*[\"]?([^\"]*)[ |\"|].*" ... thanks for your help - regular expressions are not my best area! jamie. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Netscape differences?
In article [EMAIL PROTECTED], "Joel Dossey" [EMAIL PROTECTED] wrote: One way to fool browsers when making an image request is to append a random string to the query string of the img src. In these situations, adding 'rand=?php print(time()); ?' can do the trick. Jeff Greetings, I have a php script that generates a random image. All images are kept in a mysql table. It works fine when viewed by IE, but Netscape, and Lynx, always show the same image. The database information, however, is changed as it should be (correctly incrementing the times seen column for the image), and on refresh all information goes as it should, except for randomly selecting an image. This may be an apache caching problem, but I was wondering if anyone has run into this working with php in general, and what solutions I need to explore. Thanks much, Joel Dossey __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Force variables to add
In article [EMAIL PROTECTED], "Brandon Orther" [EMAIL PROTECTED] wrote: You will want to apply a cast to the variables to force the addition to be dealing with numbers. So, if $var1 = "2" and $var2 = "3", then $var3 = (int) $var1 + (int) $var2; print($var3); will show 5 see: http://www.php.net/manual/language.types.type-juggling.php Jeff I have 2 variables, and I want them to add with each other. But all I get is the first variable and then the second variable. Here is and example: $var1 = "2"; $var2 = "3"; $var3 = $var1 + $var2; echo "$var3"; OUTPUT = 23 Does anyone know how I can forces them to add? Thank you, Brandon Orther WebIntellects Design/Development Manager [EMAIL PROTECTED] 800-994-6364 www.webintellects.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]