ecos Posted September 26, 2006 Share Posted September 26, 2006 Hello all,I am trying to format a string such as there are, 2 characters seperated by a space for 16 two character sets and then a new line.Example:54 68 65 20 75 6e 6b 6e 6f 77 6e 20 6d 65 73 7361 67 65 20 69 73 3a 20 54 68 65 20 44 45 53 2d74 65 73 74 20 63 6f 6e 74 65 73 74 27 73 20 706c 61 69 6e 74 65 78 74 08 08 08 08 08 08 08 08I have tried grouping everyother character, add a space between them and use chunk_split to make the correct length with a \r\n at the end, but the extra spaces I added are not trimmed. Any help would be GREATLY appreciated.THanks,Ecos Quote Link to comment https://forums.phpfreaks.com/topic/22105-string-formatting-help-please/ Share on other sites More sharing options...
Ninjakreborn Posted September 26, 2006 Share Posted September 26, 2006 [code]<?php$variable = "all that information you had";$variable = explode(0,2, $variable); // I think this will cut it like that, something with explode, implode, or substr, don't feel like looking right now$variable = wordwrap();// you just have to enter the parameters for word wrap?>That should put you in the right direction at least[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22105-string-formatting-help-please/#findComment-98927 Share on other sites More sharing options...
ecos Posted September 26, 2006 Author Share Posted September 26, 2006 businessman332211,Thanks for the quick reply, but with my limited experience, this code is not quite doing it. Explode returns an array [array explode ( string separator, string string [, int limit] )] and wordrap() accepts only strings. implode and substr don't jump out as winners either. Sorry if I misunderstand your insructions.Thanks,Ecos Quote Link to comment https://forums.phpfreaks.com/topic/22105-string-formatting-help-please/#findComment-98966 Share on other sites More sharing options...
Barand Posted September 26, 2006 Share Posted September 26, 2006 try[code]<?php$str = '54686520756e6b6e6f776e206d6573736167652069733a20546865204445532d7465737420636f6e74657374277320706c61696e746578740808080808080808';$new = explode('|', wordwrap($str,32,'|',true));foreach($new as $k => $line) { $new[$k] = wordwrap($line,2,' ',true);}$result = join("\n", $new);// view resultecho '<pre>',$result,'</pre>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22105-string-formatting-help-please/#findComment-98969 Share on other sites More sharing options...
ecos Posted September 26, 2006 Author Share Posted September 26, 2006 HEY Hey! That did it Barand. Thanks!Explode and Wordwrap were the tickets, but I just didn't see how to use them.Thank you both!Ecos Quote Link to comment https://forums.phpfreaks.com/topic/22105-string-formatting-help-please/#findComment-98980 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.