Find all links and return the one matching a regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
SamF
Forum Newbie
Posts: 1
Joined: Tue Mar 13, 2007 2:42 pm

Find all links and return the one matching a regex

Post by SamF »

Hi all,

I'm a java programmer who is using a web-based CVS and build system. What this means is that all my programs get stored on a page like this one: http://jnlp.concord.org/jnlp/org.concord/. As you can see, for every program (.jar file), there are a number of versions with increasing version numbers.

I occasionally write applets that need to reference the jars directly in a link that looks somewhat like this: http://jnlp.concord.org/jnlp/org.concor ... .230140-11

As you can see, the link contains the version number inside of it.

However, this means thast if I want my applets to stay up-to-date with my jar, I need to keep updating the static link.

It would be great if instead of linking to http://jnlp.concord.org/jnlp/org.concor ... .230140-11 I instead just linked to http://jnlp.concord.org/latestjar.php?type=datagraph, or something (forgive me if the syntax is completely off, I'm a PHP newbie).

Is there a way to create a PHP file, and have it return a link that 1) matches some regex, so I can specify the jarr file, and 2) returns the latest version, by looking at the version number?

Any advice of hints would be greatly appreciated!
Sam
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Moved to regex
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sure you can - check out preg_match() and header('location: redirect.to.latest.file.jar')
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you could likely use glob() in this instance too if not for it's pattern matching, atleast collecting filenames in a directory
Post Reply