brown2005 Posted November 30, 2006 Share Posted November 30, 2006 hi,if i have say$word = "cabbage";what i want to do is make the word come out likecabbagene ideas please? Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/ Share on other sites More sharing options...
AndyB Posted November 30, 2006 Share Posted November 30, 2006 [code]<?php$word = "cabbage";for ($i=0;$i<strlen($word);$i++) { echo $word{$i}. "<br/>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132648 Share on other sites More sharing options...
brown2005 Posted November 30, 2006 Author Share Posted November 30, 2006 yeah cool. thanks for the help.. wat if i wanted to put it into a table so each letter is on a new row mate? i know i should of said first, sorry... Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132652 Share on other sites More sharing options...
CheesierAngel Posted November 30, 2006 Share Posted November 30, 2006 [code]<?php$word = "cabbage";$output = <<<HTML <table> <tr><th>Letters</th></tr>HTML;for ($i=0;$i<strlen($word);$i++) { $output .= "<tr><td>$word{$i}</td></tr>";}$output .= <<<HTML </table>HTML;echo $output;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132658 Share on other sites More sharing options...
brown2005 Posted November 30, 2006 Author Share Posted November 30, 2006 why does it have to have the html bit init....what happens if i want a boder or want to put it in a form or something..? Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132667 Share on other sites More sharing options...
Daniel0 Posted November 30, 2006 Share Posted November 30, 2006 [code]<?php$word = "cabbage";foreach(str_split($word) as $character){ echo "{$character}";}?>[/code]There is a function made to split up strings. Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132674 Share on other sites More sharing options...
CheesierAngel Posted November 30, 2006 Share Posted November 30, 2006 [quote author=brown2005 link=topic=116824.msg476216#msg476216 date=1164895917]why does it have to have the html bit init....[/quote]It does not have to have the html bit init. You could do it like you want do it.For example:[code]<?php $word = "cabbage"; ?><table> <tr> <th>TheTableHeader</th> </tr> <?php for ($i=0;$i<strlen($word);$i++): ?><tr> <td> <?php echo $word{$i}; ?> </td> </tr><?php endfor; ?></table>?>[/code]This works as well. And there are so many more possibilies to do this.Just use the one you prefer.[quote author=brown2005 link=topic=116824.msg476216#msg476216 date=1164895917]what happens if i want a boder or want to put it in a form or something..?[/quote]This is just an example of how you could do this, this is not the solution like you would like it.This shows you how you can do things like this. Use the same logic combined with what you wantand you should be able to code what you want. If you liked an entire solution than ask in thefreelance forum ... Quote Link to comment https://forums.phpfreaks.com/topic/28968-help-splitting-up-a-word/#findComment-132675 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.