redarrow Posted March 31, 2006 Share Posted March 31, 2006 I am trying to get to grips with implode and exsplode but need more proper examples and exsplenations thank you..Is all this string miniplnation?example implode I understand this the implode gets the string and then adds the and.[code]<?$num=array("one","two","three","four");$result=implode(" and " , $num);echo $result;?>[/code]exsplode examplequit dont get to grips with this the explode gets the string the with any space out puts the result with a for loop.do you need always to use for loops on explode?[code]<?$sentence="my little cat";$result=explode(" " , $sentence);for($i=0; $i< count($result); $i++) {echo " number is ".$i." and ".$result[$i]."<br>";}?>[/code]thank you for your support. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 31, 2006 Share Posted March 31, 2006 Implode syntax:string [b]implode[/b] ( string glue, array pieces )the glue bit is the sting or range of characters that gets inserted between values within an array. which is the pieces part. So for example. If you have any array that stores names or words and yiu want an easy way of displaying this arrat you'll want to use implode. Now you want to display your name or words seperated by a coma. This is how you'll do it:[code]<?php$num = array("one", "two", "three"," four");$result = implode(", " , $num);echo $result;?>[/code]That will will result in this: [i]one, two, three, four[/i]Explode syntax:array [b]explode[/b] ( string separator, string string [, int limit] )Explode is alittle diferent to implode as Explode custs up strings, depending on the seperator specified and puts each cut section into an array. So take this for example:So you have string like so:[i]hello I am redarrow[/i] and you want each word to be put into an array you'll soiemthing like this:[code]<?php$string = "Hello I am redarrow";$words = explode(" ", $string);?>[/code]You'll now get an any like so:[i]array("Hello", "I", "am", "redarrow")[/i]You dont have to use a for loop no. As you can echo out each word sperately like so:[code]echo $words[0];echo $words[1];//ect.[/code]Thats all there is to it. To get a better explanation always check the PHP manul for thse two functions[a href=\"http://www.php.net/implode\" target=\"_blank\"]implode[/a][a href=\"http://www.php.net/explode\" target=\"_blank\"]explode[/a] Quote Link to comment 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.