[SOLVED]RegExp for {%download=[INSERT]%}

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

[SOLVED]RegExp for {%download=[INSERT]%}

Post by vigge89 »

I've tried to create a regular expression which should replace the following:
{%download=img%}
into:
/p/dl/\\1={$res['id']}
{$res['id']} should be the contents of $res['id'] (right now set as 4 for example).
Here's what I currently have:

Code: Select all

<?php
$inc_out = preg_replace ("/\{%download=(.*)%\}/", "/p/dl/\\1={$res['id']}", $inc_out);
?>
but it doesn't work, i get this as the result:

Code: Select all

/p/dl/img%&#125;
it should result in:

Code: Select all

/p/dl/img=4
Thanks in advance
Last edited by vigge89 on Mon Sep 06, 2004 1:29 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php
$inc_out = preg_replace ("/\{%download=(.*?)%\}/", "/p/dl/\\\\1={$res['id']}", $inc_out);
?>
Last edited by feyd on Mon Sep 06, 2004 1:30 pm, edited 1 time in total.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

I believe you forgot something ("/p/dl/\\1={$res['id']}")
but i tried the pattern out, and it seems to work, thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that part got hidden when the highlighter went over it.
Post Reply