Re: Php and regex help or advice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HTML usually change very often. Especially properties.

A link can change from: <a href="/">Home</a>
to: <a class="something" href="/">Home</a>

So, your regex must avoid using the properties to match elements

So, I think this should be a better expresion

preg_match_all(
   '#<p[^>]*><font[^>]*>(.+)<br/?>(.+)<br/?>(.+)Critical Violations
Found:#imsU',
   $html, // <-- your variable with the text
   $match // <-- here PHP sets the matches
);

print_r( $match );  // <-- take a look at the results, loop over these are
quite easy

http://php.net/manual/en/function.preg-match-all.php

Also using # as delimiter leaves you the / for simpler use, avoiding an
extra backslash.

On Wed, Jun 17, 2009 at 12:03 PM, Miller, Terion <
tmiller@xxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Everyone,
> Ok, so I've been plunged further into using php by being tasked to use it
> with regex (yes tylenol extra strength needed please) So far I have my code
> that grabs a full block of text by paragraphs, now I have to somehow write
> a
> snippet that goes inside this block and pulls out each line and puts each
> line in a db, the different lines of text are broken with <br> tags so that
> should be fairly simple? Right, here is what I have so far, I have played
> with some of the regex tester tools online but am not having any luck once
> inside the first block, which makes me think I'm doing it wrong.
>
> My wobbley code thus far I know it must have a long way to go:
> This grabs everything paragraph by paragraph:
> <?php
> $results = preg_match_all('/<p><font size="2" face="Arial, Helvetica,
> sans-serif">(.+)<br>(.+)<br>(.+)Critical Violations Found:/imsU');
>
>
> Now I need to grab each line in the paragraph and am stuck:.....
>
> //---at some point I have to strip the tags off of what will be put in the
> db--//
> $raw = strip_tags($results);
>
>
> echo $raw;
> ?>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Martin Scotta

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux