Hi all,
I'm using the following to try and replace urls in my html output:
$newhrefs = preg_replace("/script.php\?(.*)=(.*)&(.*)=(.*)&(.*)=(.*)/", "script-$1-$2-$3-$4-$5-$6.html", $hrefs);
This works fine as long as there are exactly 3 var=val pairs... not 1 or 2 or 4 or more...
How can I write my expression to match 1 or more pairs??? For example:
script.php?var=val
script.php?var=val&var2=val2
script.php?var=val&var2=val2&var3=val3
script.php?var=val&var2=val2&var3=val3&var4=val4
etc...etc...etc...
TIA,
Shawn
regex help please!
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Or one str_replace():
Mac
Code: Select all
$string = 'script.php?var=val&var2=val2&var3=val3&var4=val4';
$from = array('.php?', '=', '&');
$to = '-';
$replaced = str_replace($from, $to, $string);