Increment a variable once every time a string is matched

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NRiethmann
Forum Newbie
Posts: 2
Joined: Fri Sep 13, 2002 3:40 pm

Increment a variable once every time a string is matched

Post by NRiethmann »

I'm new to regular expressions, but I've already figured out how to parse an block of HTML for links and place those links in an array for use later. What I'd like to do is use one of the replace functions to replace the closing anchor tags with the closing anchor tags plus a superscript number that can be used to match each link to its URL. To do this, I need to increment a variable each time a match is made. The endstate of this will be a "printer-/user-friendly" page that uses footnotes to show a user what the URL of each link on a printed page will go. The problem with printing a web page is that, while links may stand out because of their formatting, you really don't know where they will take you.

Any ideas on incrementing a variable every time a match is made?

Thanks in advance.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

http://www.php.net/manual/en/pcre.pattern.modifiers.php

Particularly, look at the e modifier.
Post Reply