1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP N00b help!

Discussion in 'PHP' started by luigi193, Mar 12, 2008.

  1. #1
    I am building a simple price calculator for a client's client... I had found a way to figure everything else out and get it all working, except for one part.

    Let me explain the idea of the project first: The user is suppose to enter a password, and depending on the password that is entered, read a certain text file with prices. I used the file() command, that brings in every line as a new part of the array, I then used array_unshift to make the first line be 1 instead of zero. There is an admin area, where they can change the prices in the text file... but I would really like line numbers. I want the actual file to look like this:
    1)1234
    2)2345

    BUT when its called to be echoed into the table, have it strip out the "number)" part... I tried to do a loop that striped out the first part using str_replace, but that only worked for 1-10... I have to up to 98. Can anyone help me find a way to do this? This is my first time writing in PHP (or anything) and I hate asking for help, but I have been looking everywhere for a solution, and I can't get one to work! Any help would be appreciated.
     
    luigi193, Mar 12, 2008 IP
  2. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are several different ways to do this..
    I would use ereg if it were me.. But since this is a newb lesson:

    assume $strParen is "1)1234" or "98)123123" or anything)numbers
    
    $newStr = substr($strParen, 1+strpos($strParen, ")"));
    
    Code (markup):
    -Jason
     
    DopeDomains, Mar 12, 2008 IP
  3. luigi193

    luigi193 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't think that works... this is an array. $thefile is what its called, and goes like this: 1 => 1234
    2 => 2345
    ECT.
    When I print_r the array... it comes back with the rray...
    Any more help... sorry for being so dumb...
     
    luigi193, Mar 12, 2008 IP
  4. luigi193

    luigi193 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I meant, after I did what you said, that's what it printed... It would even work to trim the first 4 characters of, if I set them all to 001)... but again, how to I get it to work in an array?
     
    luigi193, Mar 12, 2008 IP
  5. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I need to see the print_r output to tell you for sure.. But if you had an array that was
    
    $i[1] = "1)1238";
    $i[2] = "2)120837";
    $i[3] = "3)0909";
    ...
    $i[9981] = "9981)123897"
    
    PHP:
    and you wanted to print out:
    1238
    120837
    0909
    ...
    123897

    I would use:
    
    foreach ($i as $strParen) {
    $newStr = substr($strParen, 1+strpos($strParen, ")"));
    print("$newStr<br>");
    }
    
    PHP:
    -Jason
     
    DopeDomains, Mar 13, 2008 IP
  6. luigi193

    luigi193 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Cool, I'll try it!
     
    luigi193, Mar 13, 2008 IP