...

View Full Version : php 'n' reg exp



scorpion
02-18-2003, 09:32 AM
Hey, I've been looking at reg exp for a while now...ok....a few days...and i can't be the only one who thinks it looks like a tin of spaghetti.

Say I have an anchor tag:

<a href="dynamic.php?page=mytest">My Test</a>

How can I use reg exp to change that anchor tag to:

<a href="mytest.html">My Test</a>

I hope someone can help :)


Scorpion

------------------------------------
Act first - ask questions later
------------------------------------

Jesh
02-18-2003, 03:44 PM
Dunno exactly what you want,

but does the user click on the link? or is that link a string? :confused:

Jesh

CONFIQ
02-18-2003, 08:33 PM
Originally posted by scorpion
<a href="dynamic.php?page=mytest">My Test</a>
How can I use reg exp to change that anchor tag to:
<a href="mytest.html">My Test</a>


I didn't try this code,but it will give you a hint


function myget($str) {
$temp = preg_replace("/(>(.+)<)/iU",\\2,$str);
$str = preg_replace("/(\"(.+)page=(.+)\")/iU",\\3,$str);
$str .= .html;
return("<a href=\"$str\">$temp</a>");
}

I really hope it's working :\

scorpion
02-19-2003, 12:57 PM
Hey,

thanks, that nearly works (I think), but it get an illegal character error. Can you recommend any good books on php reg exp?


Scorpion

------------------------------------
Act first - ask questions later
------------------------------------

scorpion
02-21-2003, 11:42 AM
Anyone?



Scorpion

------------------------------------
Act first - ask questions later
------------------------------------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum