[php] Help with a parsing program

brunoais

New Member
Messages
115
Reaction score
0
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:
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:

___________________________________________________

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:

or it there may also be:
title="Celeiro nível 7"
the program will output:

and there will be:
<td style="padding-top:4px;">5971/9000</td>
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:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
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.
 

mephis

New Member
Messages
39
Reaction score
0
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
 

brunoais

New Member
Messages
115
Reaction score
0
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:

t2t2t

New Member
Messages
690
Reaction score
0
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;
 

brunoais

New Member
Messages
115
Reaction score
0
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:
Top