+ Reply to Thread
Results 1 to 7 of 7

Thread: [php] Help with a parsing program

  1. #1
    brunoais is offline x10 Sophmore brunoais is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    111

    [php] Help with a parsing program

    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:
    title="Paliçada nível
    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:
    <td style="padding-top:4px;">
    extract the number that comes next (it ends with a "/")

    and then extract the number that comes next to the "/"
    it ends with a:
    </td>
    __________________________________________________ _

    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):
    title="Paliçada nível 20"
    the program will output:
    20
    or it there may also be:
    title="Celeiro nível 7"
    the program will output:
    7
    and there will be:
    <td style="padding-top:4px;">5971/9000</td>
    the program will output:
    5971
    and there will be an other output:
    9000
    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 by brunoais; 12-27-2008 at 03:52 AM. Reason: Automerged Doublepost

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: [php] Help with a parsing program

    No one is answering because they probably don't understand what you are asking. Please explain what you want more fully and comprehendly.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    mephis's Avatar
    mephis is offline x10Hosting Member mephis is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: [php] Help with a parsing program

    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. #4
    brunoais is offline x10 Sophmore brunoais is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    111

    Re: [php] Help with a parsing program

    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 by brunoais; 12-27-2008 at 09:03 AM.

  5. #5
    tttony's Avatar
    tttony is offline x10 Sophmore tttony is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    ~ 10°10'27.10''' N 67°59'59'.59''' O elev. 457m
    Posts
    147

    Re: [php] Help with a parsing program

    well you need regular expressions, you can lran more about this here:

    http://www.addedbytes.com/cheat-shee...eet-version-1/

    http://www.addedbytes.com/cheat-shee...s-cheat-sheet/

    I learnt so much with these tutorials
    PHP & MySQL Web Developer
    Free Domain co.cc

  6. #6
    t2t2t's Avatar
    t2t2t is offline x10 Elder t2t2t is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    Europe, Estonia
    Posts
    690

    Re: [php] Help with a parsing program

    Here's something I quickly wrote:
    PHP Code:
    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;
    This post has been marked spam 52 times.


  7. #7
    brunoais is offline x10 Sophmore brunoais is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    111

    Re: [php] Help with a parsing program

    so it seems like to find the number after
    "title="Paliçada nível" is must be:
    PHP Code:
    ^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 by brunoais; 12-27-2008 at 11:09 AM.

+ Reply to Thread

Similar Threads

  1. It works! ...
    By bpakidz in forum Programming Help
    Replies: 4
    Last Post: 09-07-2008, 11:12 PM
  2. Free Graphics Software
    By Danfelbm in forum Graphics & Webdesign
    Replies: 12
    Last Post: 04-13-2008, 12:37 PM
  3. Help!! dont know how to use mysql to run my program
    By CldBlded in forum Free Hosting
    Replies: 7
    Last Post: 03-27-2008, 12:40 PM
  4. Want a program made for you?
    By dsfreak in forum Off Topic
    Replies: 25
    Last Post: 05-26-2005, 06:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers