SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble with Reg Expressions

    <?php
    $string = "4546 Pine Tree Ave";
    $string = preg_replace("/(\d+) /", "$1, ", $string);
    echo $string;
    ?>

    In the above function I am adding a comma after the 1st set of digits.
    So my question is how can i split $string into two variables. The end result would be.

    $digits and $street

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No need for regular expressions.

    Code PHP:
    $string = '4546 Pine Tree Ave';
     
    $pos = strpos($string, ' ');
    $digits = substr($string, 0, $pos);
    $street = substr($string, $pos);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •