preg_match_all not working

Hi, i am working some weeks over a project but i have a really big annoying problem…i really dont know what to do so any help will be appreciated!!! :slight_smile:

I am using curl to get a html code and filter this with pregmatchall so as i can get some numbers. Some code is here:

if (preg_match_all('/><td colspan="2" valign="top" class="topBorderLight">\(.*([0-9]{3})\) .*<span class="redfonts" \/><\/td>/', $grades_data, $matches)) { echo '<textarea rows="30" cols="100">'; print_r($matches); echo '</textarea>'; }else{ echo "Huston we have a problem!"; }

The regular expresion is OK as i saw from lumadis.be/regex/test_regex.php Instead of i tried (,*) which is more general and its working fine…what is going on? Why the first code is not working? Any help? :confused:

thx guys :slight_smile:

ok, I’m pleading mostly ignorant on this so sorry if I’m may be giving wrong info.

Two things;

I think the quotes are messing up your strings - which is confusing preg

I don’t think you can embed regex into that.

The quotes can’ t be wrong. I have tested this expression in a site and it is completlly correct. Now, what do you mean that i cant embed regex?

As I said, I’m pleading ignorance…

I only used preg in simple string matching and you’ve got a complex one going their.

I’m just say’n… improper placement of quotes is a very common issue, yours looks correct but do take my word for it.

There are post here all the time where the problem is a misspelled variable or a missing semicolon. Just trying to cover the obvious bases.

Can you be more specific? What about it isn’t working? Is there no output, no errors, some errors that we don’t know about, there’s output but not what you expected…?

You mean about the regular expression? How can it be wrong since i checked it in a website (see 1st post) and it works fine! There is no output since it always goes in the else statement and prints “Huston we have a problem!”.

If i use a more general expression like (.) its works good. But, i need only some numbers and not all the string. The (.) returns something like:

(ΧΧΧΥΥΥ)  text

like:

(PLY423) mpla mpla

What i want is only the number 423 in the above example. Thats why i am using \(.*([0-9]{3})\) .*
but it does not work! It may be an encoding error or something?

I tried to echo the result of curl (where i get the webpage) and everything is fine. However, when i write the result to a file the text is in wrong encoding. May this cause the problem?

I sorry if I’m always pointing out the obvious, but…

$this = str_replace(“stuffidontwant”, “”, $that);

will reduce the string to just the segment you want. Looks like if you do this for pre and post nugget, all that’s left is the nugget.

Hi, you reply according to my answer! :stuck_out_tongue: The page which i work is about 800 lines. So…i guess that is somehow dificult :confused:

Sometimes big problems are easily solved when broken down into smaller problems…

I see in yer pattern match you have /
and that yer delimiter is /

but your using single quotes. A Single quote only escapes a .

Use a different delimter

another is your pattern for
(ΧΧΧΥΥΥ) text
if XXX is always alpha and yyy always numeric
than

\([a-zA-Z]{3}[0-9]{3}\) .*

or how about

\(\D*\d{3}\) .*

Thank you my friend :slight_smile: I’ ll give it a try hoping it works.

Sponsor our Newsletter | Privacy Policy | Terms of Service