Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Fri Apr 07, 2006 8:48 am Reply with quote

I'm not too big on regular expressions. I can use the simple ones, but I've not found anything so far that I can understand to help with this.

To replace the awkward iframe, I'm writing a PHP wrapper (specifically a phpNuke module, but besides the point) to load pages from ViewCVS. I'm using file_get_contents to grab them.

I have to rewrite the links to use the wrapper. str_replace doesn't quite work.. I will have nasty glitches with it. I see how GoogleTap uses preg_replace for global replacement rules. But since these links don't follow any standards like phpNuke paths, I hope to do this

Replace
Quote:

<a href="/path/index.php">

with something like
Quote:

<a href="modules.php?name=CVS&query=/path/index.php">


I need to do specific changes to the links with A HREF only, depending on how it is used
"#name" needs to be preserved to the same page
"index.php?name=red&test=2" needs to preserve with urlencode so it passes the correct query
"folder/test/test2.php" needs to prefix the current query path so it loads the correct file

I'll need to do the same thing for the FORM code, but I figure if I can get my head around this part, I can do it the same way. Thoughts?

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
technocrat
Life Cycles Becoming CPU Cycles



Joined: Jul 07, 2005
Posts: 511

PostPosted: Fri Apr 07, 2006 9:07 am Reply with quote

This is untested, but in the neighborhood.
Code:
$string = preg_replace('#<\s*?a\s*?href=("|')(.*)("|').*>#i','<a href="modules.php?name=CVS&query=$2">',$string);


Good place to test out everything is http://www.rexv.org

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! / Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message
evaders99







PostPosted: Fri Apr 07, 2006 4:19 pm Reply with quote

Thanxs I'll take a look and try it out Smile
 
VinDSL
Life Cycles Becoming CPU Cycles



Joined: Jul 11, 2004
Posts: 614
Location: Arizona (USA) Admin: NukeCops.com Admin: Disipal Designs Admin: Lenon.com

PostPosted: Fri Apr 07, 2006 4:43 pm Reply with quote

I find this site EXTREMELY useful for reg expressions:

http://regexlib.com/Default.aspx

It's an odd place, and takes a while to get used to, but give it a whirl. As a matter of fact, I suggest bookmarking it... Wink

_________________
.:: "The further in you go, the bigger it gets!" ::.
.:: Only registered users can see links on this board! Get registered or login! | Only registered users can see links on this board! Get registered or login! ::. 
View user's profile Send private message Visit poster's website ICQ Number
fade2gray
Regular
Regular



Joined: Mar 26, 2006
Posts: 87
Location: UK

PostPosted: Sat Apr 22, 2006 9:50 am Reply with quote

Idea

Not being a coder/programmer I've been often frustrated when needing to use a regexp.

What I have found very helpful is the expression wizard built into Only registered users can see links on this board! Get registered or login!.

Quote:
Agent Ransack is a free tool for finding files and information on your hard drive fast and efficiently. When searching the contents of files Agent Ransack displays the text found so you can quickly browse the results without having to separately open each file!

Agent Ransack provides compelling advantages over similar search tools:
  • Regular expressions that allow complex rule based searches.
  • Immediate contents results view.
  • Various wizards to walk the user through the searching process.

 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©