Page 1 of 1
Explode.. returns the letters?
Posted: Tue Mar 23, 2004 11:25 pm
by Steveo31
This is weird.. from the PHP manual, the following should return "foo" and "bar". Instead, it returns "f" and "o":
Code: Select all
<?php
$foo = "foo bar";
explode(" ", $foo);
echo $foo[0]."<br>".$foo[1];
?>
What am I doing wrong?
Posted: Tue Mar 23, 2004 11:31 pm
by m3mn0n
[php_man]explode[/php_man]() returns an array.
$foo must be an array.
Currently it's a string.
Posted: Tue Mar 23, 2004 11:36 pm
by Goowe
http://www.disturbedfrenzy.com/disturbe ... ource=true
[I fixed it... lol, sorry for my stupid mistake Sami.]
Gotta use single quotes and set the explode() array to a variable....
Posted: Tue Mar 23, 2004 11:40 pm
by m3mn0n
That code is wrong. Well it does the job, but it doesn't use explode(). Remove the explode line, and you will see the exact same result.
Steveo13: click on the the manual link to the [php_man]explode[/php_man]() page and view the examples + user notes.
Posted: Wed Mar 24, 2004 4:51 am
by m3mn0n
heh
Nice to see you got it working.

Posted: Wed Mar 24, 2004 5:01 am
by Wayne
Code: Select all
<?php
$foo = "foo bar";
$exploded = explode(" ", $foo);
echo $exploded[0]."<br>".$exploded[1];
?>
you need to assign the value returned from the function explode() to a variable, it does not automatically go back to the variable you used it on, $foo in you example still equals "foo bar"
Posted: Wed Mar 24, 2004 9:44 am
by Steveo31
Sami wrote:
Steveo13: click on the the manual link to the [php_man]explode[/php_man]() page and view the examples + user notes.
heh... did that last night and realized... doh.