Forum Moderators: coopster

Message Too Old, No Replies

help with preg_replace

         

scorpion

9:05 pm on Oct 3, 2003 (gmt 0)

10+ Year Member



I want to append a string to the beginning of every link that begins with a number in a string...I came up with the following just wondering if anyone sees some errors:

$string = "<A HREF=534/533.html></A><A HREF=884/53333.html></A>";

$pattern = "/HREF=[0-9]/i";
$replacement = "HREF=../cgi-bin/getfile.cgi?$1";

My idea is for every link that whose first digit is a numeral to append the fixed string in front of that and then match the rest.

For some reason, this doesn't seem like it'll work. Maybe the pattern is not complete?

coopster

9:29 pm on Oct 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Correct, you forgot your parenthesized pattern match:

$pattern = "/HREF=[b]([/b][0-9][b])[/b]/i";

scorpion

9:53 pm on Oct 3, 2003 (gmt 0)

10+ Year Member



thanks my concern was that the match would do this:

HREF=../cgi-bin/getfile.cgi?HREF=3433/5533.htm

or something that is take $1 and replace it with the whole part matched instead of just the number part after..

i.e.
HREF=../cgi-bin/getfile.cgi?3433/5533.htm

would be the correct output I'm seeking

MonkeeSage

10:33 pm on Oct 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



coopster's works like you want

Jordan