Jump to content


Photo

String formatting help! Please.


  • Please log in to reply
4 replies to this topic

#1 ecos

ecos
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 September 2006 - 02:16 PM

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 73
61 67 65 20 69 73 3a 20 54 68 65 20 44 45 53 2d
74 65 73 74 20 63 6f 6e 74 65 73 74 27 73 20 70
6c 61 69 6e 74 65 78 74 08 08 08 08 08 08 08 08

I 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

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 September 2006 - 02:23 PM

<?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

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 ecos

ecos
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 September 2006 - 02:47 PM

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 

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 26 September 2006 - 02:50 PM

try

<?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 result
echo '<pre>',$result,'</pre>';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 ecos

ecos
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 September 2006 - 03:00 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users