PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Steveo31
Forum Contributor
Posts: 416 Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA
Post
by Steveo31 » Tue Mar 23, 2004 11:25 pm
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?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Tue Mar 23, 2004 11:31 pm
[php_man]explode[/php_man]() returns an array.
$foo must be an array.
Currently it's a string.
Goowe
Forum Commoner
Posts: 94 Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska
Post
by Goowe » Tue Mar 23, 2004 11:36 pm
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....
Last edited by
Goowe on Tue Mar 23, 2004 11:50 pm, edited 2 times in total.
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Tue Mar 23, 2004 11:40 pm
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.
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Wed Mar 24, 2004 4:51 am
heh
Nice to see you got it working.
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Wed Mar 24, 2004 5:01 am
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"
Steveo31
Forum Contributor
Posts: 416 Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA
Post
by Steveo31 » Wed Mar 24, 2004 9:44 am
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.