|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I know we have to use reg. expression, but any suggestions would be very helpful!
for example: <a href="link.htm"> --> <a href="http://domain.com/link.htm"> (that is just a SIMPLE form of link, take other formats of hyperlink into consideration too) ------------------ http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips) ------ Son |
|
#2
|
|||
|
|||
|
this should work, assuming that the double quote of the a href is the first double quote in the string
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$var = "<a href="link.html">"; $domain = "http://domain.com/"; $var =~ s/"/"$domain/; // $var is now // <a href="http://domain.com/link.html">[/code] [This message has been edited by RyanP (edited August 22, 2000).] |
|
#3
|
|||
|
|||
|
You can also collapse out any ..'s in your path using:
$var =~ s![^/]*/../!!g; Just makes it look prettier. :-) |
|
#4
|
|||
|
|||
|
this hack would work:
$domain = "http://www.yourdomain.com/"; s/a href="/a href="$domain/; |
|
#5
|
|||
|
|||
|
I gonna try these solutions now! Thanks guys
For the last solution, "<A" need not go together with "HREF", so if you use it, in most cases, it's okay, but the error is there!! ![]() ------------------ http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips) ------ Son |
|
#6
|
|||
|
|||
|
>>this hack would work:
>>$domain = "http://www.yourdomain.com/"; >>s/a href="/a href="$domain/; This would fail in many ways: 1) <A href="link.htm"> 2) <a HREF="link.htm"> 3) <a href ="link.htm"> 4) <a href= "link.htm"> Always expect what worse things can happen. All four above are valid hyperlinks. Even the URL without quotes. Check this out -> http://www.devshed.com/Talk/Forums/Forum5/HTML/001858.html [This message has been edited by freebsd (edited August 23, 2000).] |
|
#7
|
|||
|
|||
|
chris: what are those bangs in your RE for? i've never seen them used like that
|
|
#8
|
|||
|
|||
|
Ah, this is the rather tasty feature of Perl that allows you to choose your quote characters. There's no rule that says you have to use / to delimit your regular expressions (or that you have to use " to delimit an interpolated string, or ' to delimit a non-interpolated string, for that matter). You can specify your quote character as you need. So you can do:
s!find!replace!g or even s(find){replace}g (Perl will allow you to use naturally paired delimiters). For quotes, you can do: q/my string/ for a non-interpolated string, and qq/my string/ for an interpolated string You don't have to use / there, you can use any non-alphanumeric, non-whitespace character. There is a shortcut regarding /'s whereby $var =~ /regexp/ is interpreted as $var =~ m/regexp/ Check out the perlop manpage for more info: perldoc perlop |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > How to parse relatives links to absolute links? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|