![]() |
Help with function stristr()
Hello everyone,
I am using the above mentioned function in the following way: PHP Code:
Warning: Wrong parameter count for stristr() I've checked the manual and everything seems to be ok, so what am I doing wrong ? Can someone help? pipesportugal |
The third argument (
before_needle) is only available with PHP 5.3.0 and upward.An equivalent snippet would be something like: PHP Code:
|
Hi Salathe,
I really was not expecting anyone to reply so soon, as my idea is(was...) that most talkphp members were on the left side of the Atlantic Ocean therefore by time I've sent this thread through, I thought everyone was still spleeping. As You can (easily) imagine my routine was reading the result of a mySQL query "SHOW COLUMNS FROM table" and then I was using this routine to desintegrate column 2: example: int(7) into: $type=int and $length=7, as I want to develop a simple form generator class(by my own). In the meanwhile I changed approach and went by this road: $this->query = "SELECT COLUMN_NAME, DATA_TYPE, NUMERIC_PRECISION, NUMERIC_SCALE, CHARACTER_MAXIMUM_LENGTH, COLUMN_COMMENT from information_schema.columns where table_name = '$table'"; This sql instruction gives me directly the fields that I was looking for. Regarding Your precious advice, those lines execute its purpose but I must confess that it's difficult for me to "read" Your php lines, as I have never done anything like that before. Looks complicated...from rookie my point of view. Some instructions how to read them in plain English would be nice... Thanks for caring, Cheers, Jose. |
Salathe doesn't sleep. He's out there, maintaining the balance.
It might be harder to read if you're not first familiar with the ternary operator. It's a really handy shorthand for a basic IF statement. PHP Code:
If $pos = strpos($text0, '(')) doesn't return false, than that means '(' was found somewhere in $text0 and the statement evaluates to true. If it evaluates to true, the ternary executes the code found after the ? and before the :, which in this case returns a substr of $text0, from the start of the string to the position where the first ( was found. If it evaluates to false, it executes the code found after the : and before the end of the block, which in this case would return a value of FALSE. -m |
Salathe has made use of the ternary operator, it works like this:
( expression) ? ( expression2 ) : (expression3) If expression is true, then PHP will evaluate to ( expression2 ) If expression1 is false, then it evaluates to ( expression3 ) To help you understand it further it can be rewritten like so: PHP Code:
As you can see using the ternary is smaller but at the same time can be tricky to read, especially if you nest them, which you shouldnt do, not unless you want to give yourself a headache, look at this snippet posted by salathe in another post: PHP Code:
|
Yeah, but you explained it a lot better. ;-) -m
|
Bonus points to sketch for finding my example of "when ternary goes bad!". :-)
|
Dear Friends,
Understood the basic about the ternary operator and some tests made with sucess. Are there any limit to the "thank You" I can give to my forum colleagues? I am new but I suspect I am gone give quite a few in the next times. Thank You all, pipesportugal |
| All times are GMT. The time now is 05:49 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0