Welcome Guest, Not a member yet? Register   Sign In
strstr function
#1

[eluser]Dynamica Technology[/eluser]
Hi

I have this code

Code:
$needle = ',';
  $haystack=$fb_data['me']['location']['name'];
  $before_needle='TRUE';

  $db_data=array(
    'city'=>strstr($haystack, $needle, $before_needle)
   );

when run the app I have this error

Quote:Severity: Warning

Message: Wrong parameter count for strstr()

Filename: models/facebook_model.php

Line Number: 85

if not use the needle the function work.

Could you help me.
Thanks
#2

[eluser]GDmac - expocom[/eluser]
PHP 5.3.0 Added the optional parameter before_needle.
http://php.net/strstr

bonus: your $before_needle = "True"; is actually a string.
"False" != False. http://php.net/boolean
#3

[eluser]Dynamica Technology[/eluser]
I know is a string, but also if write TRUE or true have the same error

I read more post that have same problem in a linux server, but in windows server work
#4

[eluser]Aken[/eluser]
What version of PHP are you using? The third parameter was not added until 5.3.0.
#5

[eluser]Dynamica Technology[/eluser]
Thanks

I view now that my hosting not use 5.3.0 ( my hosting use 5.2.17, in local I have 5.3.14)

now how bypass this problem

I need to retrieved a string before "," and a string after ","
#6

[eluser]PhilTem[/eluser]
Assuming you have a comma only once in your string to search

Code:
$pos_comma = strpos($string_to_search, ',');
$before = substr($string_to_search, 0, $pos_comma - 1);
$after = substr($string_to_search, $pos_comma + 1);

will return everything before the comma (w/o the comma) and after the comma (again w/o the comma)

Edit: Actually this works for more than one comma in your string, but it will split the string according to the position of your first comma. Just to clarify Wink
#7

[eluser]CroNiX[/eluser]
Or you could just
Code:
list($left_text, $right_text) = explode(',', $string);
Again, assuming 1 comma in your string...
#8

[eluser]Narf[/eluser]
[quote author="CroNiX" date="1352830542"]Or you could just
Code:
list($left_text, $right_text) = explode(',', $string);
Again, assuming 1 comma in your string...[/quote]

No assumptions:

Code:
list($left_text, $right_text) = explode(',', $string, 2);

Another note - the original example shows this:

Code:
$before_needle = 'TRUE';

Which is wrong, it should be boolean.
#9

[eluser]Dynamica Technology[/eluser]
Thanks for help me
#10

[eluser]Dynamica Technology[/eluser]
[quote author="Narf" date="1352834789"][quote author="CroNiX" date="1352830542"]Or you could just
Code:
list($left_text, $right_text) = explode(',', $string);
Again, assuming 1 comma in your string...[/quote]

No assumptions:

Code:
list($left_text, $right_text) = explode(',', $string, 2);

Another note - the original example shows this:

Code:
$before_needle = 'TRUE';

Which is wrong, it should be boolean.[/quote]

I know, I said in prior post




Theme © iAndrew 2016 - Forum software by © MyBB