SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot fredmintah's Avatar
    Join Date
    Jun 2004
    Location
    Ghana
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I extract

    Hello gurus,
    Below is the sample code I will like you to help me out with. Please forgive me if you think I should know this. I am really new to the PHP world. Thank for you understanding.


    PHP Code:
        $fname "name";     
        
    $lname "format";   
        
    $tel "4778546";     
      
        
    $one = ?;    // what function to extract nam from the $fname variable
        
    $two = ?;   //  what function to extract 854 from the $lname variable
        
    $three = ?; //   what function to extract mat from the $tel variable

        
    $id $one $two $three
        
        
    print $id;
     
       
    //Now id should contain [B]nam854mat[/B] which should be printed to the browser. 

  2. #2
    SitePoint Member emil's Avatar
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use substr() to do this.

  3. #3
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fredmintah
    Hello gurus,
    Below is the sample code I will like you to help me out with. Please forgive me if you think I should know this. I am really new to the PHP world. Thank for you understanding.
    PHP Code:
        $fname "name";     
        
    $lname "format";   
        
    $tel "4778546";     
        
        
    # Using the substr() function we start at position 0 and go to position
        # 3 to get the first three letters of the $fname variable.
        
    $one substr($fname,0,3);    // what function to extract nam from the $fname variable
        # Same thing here
        
    $two substr($tel,3,3);   //  what function to extract 854 from the $lname variable

        # Same thing here
        
    $three substr($lname,3,3); //   what function to extract mat from the $tel variable

        
    $id $one $two $three;
        
        print 
    $id

  4. #4
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow that helps me aswell, i wanted to help him until i realised i had the same problem so great . Where can you find out stuff like this? I couldnt find it anywhere.

  5. #5
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think part of it is just knowing what function to use.

    http://www.php.net/substr talks all about the substr() function.

    I bet a google search for "PHP extract string" or "PHP part of string" would find somethin that could get you started.

  6. #6
    SitePoint Zealot Scott.Mc's Avatar
    Join Date
    Jul 2004
    Location
    Scotland
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php.net is a great place to learn the functions , www.php.net/function such easy to find each one.

    just substr and use strlen for the length of the strings.
    Linux Server Management - AdminGeekZ.com
    Is your website Sluggish? Unavailable? Insecure?

    Why not call us? +44 0141 2800134


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
  •