SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Location
    Holland
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cutting with regular expression

    Hi all,

    Am trying to learn Regular expressions, but am not getting anywhere.
    I came up with the following code:

    <?php
    $lines = file ('test.txt');

    foreach ($lines as $line) {

    $a = explode (',', $line);

    echo $a[0];

    }
    ?>

    its not much but hopefully a good start. The line I want to separate is as followed:

    CN=HMBE09S001,AU=Domain name,AU=asia,AU=Glazenhandel,AU=pri ;10/01/2005;01/02/2005

    As output variable $a is showing ‘CN=HMBE09S001’ and I would like it to show ‘HMBE09S001’ so basically i need to cut of the ‘CN=’ part, but how?

    Can anybody give me at least a clue how to do so?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Bloomington, IL
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    $a['0'] = str_replace('CN='''$a['0']); 
    The str_replace function will search for "CN=" and replace it with nothing.


    You could also use the substr function to return all but the first three characters of the string:
    PHP Code:
    $a['0'] = substr($a['0'], 3); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Location
    Holland
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool..
    Thanks for the info and quick reply,

    will be enough to keep me busy for a while..


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
  •