SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Reg ex help

  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reg ex help

    Gidday All,

    Each page in my site has a page Id.

    With each page Id I store the pages Link Text and url.

    To determine the breadcrumb on the site all i need do is breakup the pageId into its parts.

    ie. pageId = "3.46.25.123";

    3
    3.46
    3.46.25
    3.46.25.123

    So i guess I need to loop until there are no more "." appearing in the page id each time returning from the beginning of the string to the occurence of the last ".".

    Any ideas? I've come up with this so far


    Code:
     $pageId =~ /^(.*)\./);


    Colin

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code looks Perl-ish

    Don't know if you want it for PHP but you can use:

    PHP Code:
    $id '3.46.25.123';
    $trail explode('.'$id);
    for (
    $i 0$max count($trail); $i $max$i++)
    {
       
    // do something with $trail[$i] here


  3. #3
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks Chris,

    Yes I was looking for a php solution but thought we could use a regex to make it smarter.

    Colin


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
  •