PeterWhmrc
Programmer
- Nov 12, 2011
- 1
Hi all,
Although theyre supposed to be fairly simple Im definitely having problems getting my head around Regular Expressions and more importantly how they are used to replace or amend data.
I am trying to do something I think should be fairly simple.
Im reading in a webpage using cURL amending some text and outputting it to the browser (basically a simple censor type page)
This works fine however I want to be able to enhance it so that if a user clicks a link on the viewed page it doesnt take them to that link as such but loads the page into the php script.
Im probably not making much sense here!
MyPage1.html = simple page with a textfield to enter a URL (say MyPage2.php = php script that loads selected URL (via GET) and changes the text before displaying
If user clicks a link on that page (say then they are directed to the bbc site whereas I want them to be directed to
mypage2.php?theurl='
basically allowing the user to surf the net while still always being on mypage2.php
this is my first foray into Regular Expressions (I think Ive shied away from them in the past).
So I basically want to use Regex to find any <a href=" (or <a href=') then add " between the href= and the " or '
that would work for the bulk of href's trouble is theres other combinations possible too though, <a title="my site" href="mysite.com"> is also valid along with numerous other possibles.
If we can get the basic one though that would do for starters. If anyone could give me hints, pointers or a link to a good easy tuo understand tutorial Id be grateful.
Also to the Admins, when searching for Regular Expressions I found numerous posts in numerous forums, would this not be something that could have its own forum seeing as it crosses languages?
Although theyre supposed to be fairly simple Im definitely having problems getting my head around Regular Expressions and more importantly how they are used to replace or amend data.
I am trying to do something I think should be fairly simple.
Im reading in a webpage using cURL amending some text and outputting it to the browser (basically a simple censor type page)
This works fine however I want to be able to enhance it so that if a user clicks a link on the viewed page it doesnt take them to that link as such but loads the page into the php script.
Im probably not making much sense here!
MyPage1.html = simple page with a textfield to enter a URL (say MyPage2.php = php script that loads selected URL (via GET) and changes the text before displaying
If user clicks a link on that page (say then they are directed to the bbc site whereas I want them to be directed to
mypage2.php?theurl='
basically allowing the user to surf the net while still always being on mypage2.php
this is my first foray into Regular Expressions (I think Ive shied away from them in the past).
So I basically want to use Regex to find any <a href=" (or <a href=') then add " between the href= and the " or '
that would work for the bulk of href's trouble is theres other combinations possible too though, <a title="my site" href="mysite.com"> is also valid along with numerous other possibles.
If we can get the basic one though that would do for starters. If anyone could give me hints, pointers or a link to a good easy tuo understand tutorial Id be grateful.
Also to the Admins, when searching for Regular Expressions I found numerous posts in numerous forums, would this not be something that could have its own forum seeing as it crosses languages?