[php] Help with a parsing program

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by brunoais, Dec 27, 2008.

  1. brunoais

    brunoais New Member

    Messages:
    115
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    I'd like to make a code in order to search for keywords in a huge text.

    It works like this:
    I prompt for a big text from the user.
    the program must find the exact text:
    then a number between 0 and 20.
    after that there is a
    Also, the text may not exist, if that happens it just ignores it.

    where is "Paliçada" it may also be:
    "Muralha" or
    "muro de terra"
    I'd like to make the same code but also to search for (instead of paliçada):

    • Palácio

    • Celeiro

    • Praça de Torneios
    for the last I'd like it to search for:
    extract the number that comes next (it ends with a "/")

    and then extract the number that comes next to the "/"
    it ends with a:
    ___________________________________________________

    In order to try to make this more easy to understand it's better to make an example:

    in text there will be (between other text):
    the program will output:
    or it there may also be:
    the program will output:
    and there will be:
    the program will output:
    and there will be an other output:
    I hope I made myself clear enough

    Edit:

    I have aldeady tryed using the coding like:
    [0-9] , .^?
    but I cannot fully understand it...
    Edit:
    Why noone is answering?
     
    Last edited: Dec 27, 2008
  2. leafypiggy

    leafypiggy Manager of Pens and Office Supplies Staff Member

    Messages:
    3,819
    Likes Received:
    163
    Trophy Points:
    63
    No one is answering because they probably don't understand what you are asking. Please explain what you want more fully and comprehendly.
     
  3. mephis

    mephis New Member

    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0
    I believe he wants to parse HTML code to extract certain information in that code.
    I would suggest using preg_match() or maybe a combination of strpos()/substr() to extract that information. If you want to use preg_match() then you better read up on regular expressions, although in your case I would say strpos()/substr() would be faster
     
  4. brunoais

    brunoais New Member

    Messages:
    115
    Likes Received:
    0
    Trophy Points:
    0
    could you please help on that regular expressions so that I could find the text I need? I don't know why but I can't understand them.

    After I know how to write the regular expressions to use I can make the rest of the code with ease
     
    Last edited: Dec 27, 2008
  5. tttony

    tttony Member

    Messages:
    147
    Likes Received:
    0
    Trophy Points:
    16
  6. t2t2t

    t2t2t New Member

    Messages:
    690
    Likes Received:
    0
    Trophy Points:
    0
    Here's something I quickly wrote:
    PHP:
    function getNumbers($testfor) {
        
    preg_match_all('/[0-9]{1,}/'$testfor$out);
        return 
    $out[0]; // Returns array of numbers
    }
    However, for "<td style="padding-top:4px;">5971/9000</td>", it also matches 4 in padding-top:4px;
     
  7. brunoais

    brunoais New Member

    Messages:
    115
    Likes Received:
    0
    Trophy Points:
    0
    so it seems like to find the number after
    "title="Paliçada nível" is must be:
    PHP:
    ^title=\\"Paliçada nível[:space:]$^[0-9]$^\"$
    And with preg_match_all()
    the start sting will be:
    title="Paliçada nível 12"
    I'll get:
    [1]title="Paliçada nível
    [2]12
    [3]"
    in the variable, is this right?
     
    Last edited: Dec 27, 2008

Share This Page