0

I'm trying to rewrite this URL:

http://www.mysite.com/index.php?topic=54.msg432#msg432

to this one:

http://www.mysite.com/index.php?thread=54&post=432

using preg_replace. I tried this:

echo preg_replace('|http?://www\.mysite\.com/index.php/topic=(\d)|', '\1',
                  'http://www.mysite.com/index.php?topic=54.msg432#msg432');

And i can't get the thread :( I tried with the manual but php pattern is confusing. Im used to python RE patterns...

This doesn't work neither

php -r "echo preg_replace('~\?topic=(\d+).msg(\d+)~', '?thread=$1&post=$2', 'http://www.mysite.com/index.php?topic=54.msg432#msg432');" 

result:
http://www.mysite.com/index.php?thread=&post=#msg432

Also, i'll appreciate a good php pattern manual.

Thanks

4

1 に答える 1

1

試す:

echo preg_replace('~\?topic=(\d+)\.msg(\d+).*~', '?thread=\1&post=\2', 'http://www.mysite.com/index.php?topic=54.msg432#msg432');
于 2012-09-13T03:04:18.637 に答える