lipun4u Posted October 4, 2009 Share Posted October 4, 2009 why this code gives me error ?? <?php //header("Content-Type: Text/plain"); $name="asit" print_r(explode(" ", "$name is an asshole")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/ Share on other sites More sharing options...
pernest Posted October 4, 2009 Share Posted October 4, 2009 why this code gives me error ?? <?php //header("Content-Type: Text/plain"); $name="asit" print_r(explode(" ", "$name is an asshole")); ?> you have $name inside the quote, you need to change it for explode(" ", $name." is an asshole"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930220 Share on other sites More sharing options...
Adam Posted October 4, 2009 Share Posted October 4, 2009 Actually placing the variable within double quotes does work. The problem is you're missing a semi-colon after $name="asit" .. Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930221 Share on other sites More sharing options...
jon23d Posted October 4, 2009 Share Posted October 4, 2009 There is nothing wrong with $name being inside your quotes, the problem is that you are missing your terminator on the $name assignment line, where is your semicolon? This will fix it. Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930222 Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 another method for: Explode //header("Content-Type: Text/plain"); $name="Thisname! Is an asshole"; $z=explode("!", $name); echo "$z[0] $z[1]!"; We're using ! as the unique character $z[0] being before ! $z[1] being after ! Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930224 Share on other sites More sharing options...
Adam Posted October 4, 2009 Share Posted October 4, 2009 another method for: Explode //header("Content-Type: Text/plain"); $name="Thisname! Is an asshole"; $z=explode("!", $name); echo "$z[0] $z[1]!"; We're using ! as the unique character $z[0] being before ! $z[1] being after ! How does that help him at all? Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930227 Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 Obviously its showing him how to use more of the explode function he probably at one point wants to know how to display the data. without it looking like this: Array ( [0] => asit [1] => is [2] => an [3] => asshole ) i was just showing him more functionality in the explode call. Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930228 Share on other sites More sharing options...
.josh Posted October 4, 2009 Share Posted October 4, 2009 You aren't showing him more functionality...you're showing him the same functionality as before, just changing the delimiter, which as far as I can tell, is not what the OP asked for... Quote Link to comment https://forums.phpfreaks.com/topic/176471-explode-bug/#findComment-930231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.