Jump to content


Photo

Re-formatting Addresses


  • Please log in to reply
3 replies to this topic

#1 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 18 October 2006 - 11:58 AM

Hello. I'm trying to take a complete address from a database field and split it using the line break) into seperate values (line one be one variable, line 2 another etc).

I've got this code so far but it doesn't work:

$addy=$row['Address'];
// split the address
$chars = preg_split('/
/', $addy, -1, PREG_SPLIT_OFFSET_CAPTURE);
$al1 = $chars[0];

Can anyone help please?? Thanks in advance.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 12:03 PM

<?php

$addy = explode("\n", $row["Address"]);

print_r($addy);

?>

SA PHP Archives - www.phparchives.za.org

#3 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 18 October 2006 - 12:42 PM

Oh how silly... yeah. Thanks very much - I forgot explode --- DUH! ;)
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 01:22 PM

np. Using preg_split to remove space is like de-shelling peanuts with an anti-tank missle.  ;D
SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users