Regex Parsing

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

 



I wish to improve upon my regular expression skills.  I am creating a journal
object that allows me to post my journals online, while at the same time
maintaining nine different levels of privacy.  For example, if I give a user
Level 3 access, then they would be able to see all parts of my entries marked
as Level 3 or below, but nothing above that.

Below is an example entry.  I'm not sure how to go about doing this.  My
experience with regular expressions is somewhat limited.  I could use a
statement like this:

ereg("[LEVEL1].*[/LEVEL1]", $Contents, $Match);

But if you look at the contents below, you'll see that there are two places
where [/LEVEL1] is at, so that statement will mark the entire page as Level
1, rather than just the first sentence, and the last sentence.

Plus, that statement won't really work.  I need a way to say:  Replace
[LEVEL1].*[/LEVEL1] with ###LEVEL1### and return the contents into an array
for me.  That way, in the second phase of parsing, I can either put the
string back into the page at exactly the same point, or I can put "Level 1
Access Required - Log In" instead.

Any help would be greatly appreciated.  Thank you in advance.


[LEVEL1]Level 1 Access Required to view this section of this entry.[/LEVEL1]

between levels

[LEVEL2]Level 2 Access Required to view this section of this entry.[/LEVEL2]

between levels

[LEVEL3]Level 3 Access Required to view this section of this entry.[/LEVEL3]

between levels

[LEVEL4]Level 4 Access Required to view this section of this entry.[/LEVEL4]

between levels

[LEVEL5]Level 5 Access Required to view this section of this entry.[/LEVEL5]

between levels

[LEVEL6]Level 6 Access Required to view this section of this entry.[/LEVEL6]

between levels

[LEVEL7]Level 7 Access Required to view this section of this entry.[/LEVEL7]

between levels

[LEVEL8]Level 8 Access Required to view this section of this entry.[/LEVEL8]

between levels

[LEVEL9]Level 9 Access Required to view this section of this entry.[/LEVEL9]

Between levels

[LEVEL1]Level 1 Access Required to view this section of this entry.[/LEVEL1]

between levels

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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