Thanks for taking the time to help me dalar, but I think I didn't explain it clear enough and confused you.
What I need is to transform a string like this:
http://www.mydomain.com/index.php?o...page=viewtopic&t=194&highlight=test
to
http://www.mydomain.com/forum/viewtopic.php?t=194
Anyway, I found that I can live with the highlight=test part in the result string, so the following super simple regex managed to do the job
$url = "abc def ghi http://www.mydomain.com/index.php?option=com_forum&Itemid=37&page=viewtopic&t=194&highlight=test xxx www qqq http://www.mydomain.com/index.php?option=com_forum&Itemid=37&page=viewtopic&t=194";
$url = ereg_replace("http://www.mydomain.com/index.php\?option=com_forum&Itemid=[0-9]*&page=viewtopic&", "http://www.mydomain.com/viewtopic?", $url);
The result is:
abc def ghi http://www.phplinkdirectory.com/viewtopic?t=194&highlight=test xxx www qqq http://www.phplinkdirectory.com/viewtopic?t=194
What I am curious is, why does this code:
$url = "abc def ghi http://www.mydomain.com/index.php?option=com_forum&Itemid=37&page=viewtopic&t=194&highlight=test xxx www qqq http://www.mydomain.com/index.php?option=com_forum&Itemid=37&page=viewtopic&t=194";
$url = ereg_replace("http://www.mydomain.com/index.php\?.*&page=viewtopic&", "http://www.mydomain.com/viewtopic?", $url);
Gives the result of:
abc def ghi http://www.phplinkdirectory.com/viewtopic?t=194
Why does it replace the first instance only and stops?
Thanks.