milov.nl

Interaction design • webdevelopment • web art • photography

milov.nl : forum : coding : 'PHP url rewrite Preg_replace'

PHP url rewrite Preg_replace Jeroen, 040908 12:51
Hi!

I am attempting to convert a "clean URL" (string) into the "old fashioned links".

For example:
myscript.php/myfile.txt/5/2
into:
myscript.php?file=myfile.txt&id=5&year=2

Is it possible to do this with one regular expression? I always have troubles with regular expressions :(
ip503ca1e3.speed.planet.nl
Re: PHP url rewrite Preg_replace Jeroen, 040908 14:52
To eleborate on my post above, the regular expression needs to do the following:

1. Replace first / character with ?action=
2. Replace second / character with &id=
3. Replace third / character with &year=
...But only after between <A></A> tags.
Darn those expressions are hard.



ip503ca1e3.speed.planet.nl
Re: PHP url rewrite Preg_replace absolut, 040910 16:19
You can try this as example:

$str="HTML test here<a>myscript.php/myfile.txt/5/2</a> and here";
$s=preg_replace("/(.+)\/(.+)\/(\d+)\/(\d+)(\<\/a\>.*)/","\?action=\&id=\&year=\",$str);
print $s;
 
213.148.18.123
Re: PHP url rewrite Preg_replace absolut, 040910 16:21
It's not so hard. Just read PHP manual carefully.
http://support.olnevhost.net/docs/php/function.preg-replace.html
213.148.18.123
Re: PHP url rewrite Preg_replace Jeroen, 040912 16:03
I got it working (with another solution as Absolut mentioned.)

Thanks
ip503d3f54.speed.planet.nl
Pages: 1