SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: fget?

  1. #1
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to get part of a string. I am getting a response from a server, comes back html in text format, <html><head>, ect
    Now there's a part of the response I need to capture. For example, this would be the response:

    <html>
    <head><title>some site</title>
    </head>
    <body>
    Thank you for your order. You order number is 12345.
    </body>
    </html>

    I want to grab the actually order number, "12345" but I won't know the order number and it will change each time. I am at a loss on how to get just the number. I was thinking fget, but not sure if that will work? Any suggestions?
    Thanks

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use Regular Expression(RE) after you fetch the content of the page if you're sure of the format of that page (you will have to modify your script every time the page gets changed!)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Son.
    I had also thought about regex, and in testing I found "split" to work perfect. Using whitespace as a delimiter.

    $fp = "Thank you for your order. You order number is 12345";
    $pat = " ";
    $arr = split($pat,$fp);
    $id = ($arr[9]);

    echo ($id);

    the script prints "12345" Works perfect..

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  4. #4
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only issue I would have with the code is that if the format ever changes in the returned page, your code will not function correctly.

    What about:

    if (($n = strpos($page, "order number is")) >= 0) {
    $orderno = intval(substr($page, $n + 15));
    }

    This will give you a numeric order-number even if the page template changes.

    RW


    ===========================================
    http://badblue.com
    Small footprint P2P web server for Windows,
    File-sharing, PHP, wireless apps & more
    ===========================================

  5. #5
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats very true randy, I guess it's something I will have to live with.. Your code is a good idea. I just wonder, if the page would change if the "order number is" would even stay the same. But it is a thought. Thank you very much for the idea!

    I suppose I should put in some error checking at least to show if it does change. How could I check, or give an error if the result was'nt a "number"? Any ideas?
    Thanks


    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  6. #6
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have any control over the server you are grabbing stuff from? If you do then your easiest bet would be to have it generate a nice easy-to-read comment somewhere on the page - something like this:
    Code:
    <!-- ORDER:xxxxxx -->
    Then have a nice simple regexp that searches for that pattern and grabs the xxxxxx bit.

  7. #7
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I don't have control or access to the servers, as they are not mine. I only have a response from the server. Would be nice though..

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  8. #8
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need a similar kind of piece of code. The one I want is for getting telephone numbers. Here are some actual examples. The numbers are changed but you can see the problem.

    Lots of text .....800 423 2 3 4 5 .... lots of text.

    or 8+3+4+5+7#23 or some other convulted mess.

    These combinations are to disuade the use of programs grabbing the numbers. The messages may have only the 10 digits or they may be 400 lines long with the number at a non predetermined location.

    I also need to peel the date stamp from the header. But that is a bit less of a problem.

  9. #9
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I am sure not an expert to post on the last one. But I wonder about regex and pattern matching. pattern match to numerials only? Just a thought. Maybe that would be better for me also. Course the first code does work well for me. Ed could be counting alot of whitespaces..

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  10. #10
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know,

    what might just do the trick for me is to use a series of if, ifelse, and finally an else. And for those that fall through the else, run a filter to dump messages that do not have any application, they have about 5 or 6 trapable forms. Then just read the rest for the numbers. When I find a new number, add it to the mix. The fget is definite for the project. Long as i do not get an end of line.

    Its gonna be a hair-ball though.

    Peace and thanks.


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
  •