Guest Posted June 28, 2008 Share Posted June 28, 2008 I want to encode a part of what was found with preg replace but when i try this it actually encodes $2 not the value of it. Is this possible to do? Please help Quote Link to comment https://forums.phpfreaks.com/topic/112372-solved-preg_replace-urlencode2/ Share on other sites More sharing options...
sasa Posted June 29, 2008 Share Posted June 29, 2008 yes Quote Link to comment https://forums.phpfreaks.com/topic/112372-solved-preg_replace-urlencode2/#findComment-577097 Share on other sites More sharing options...
Guest Posted June 29, 2008 Share Posted June 29, 2008 Can you please tell me how this is what I have and its not working $result = preg_replace('#href="([^"*])"#is', urlencode($1), $result) Quote Link to comment https://forums.phpfreaks.com/topic/112372-solved-preg_replace-urlencode2/#findComment-577099 Share on other sites More sharing options...
sasa Posted June 29, 2008 Share Posted June 29, 2008 try <?php function my_urlencode($a){ return urlencode($a[1]); } echo $result = preg_replace_callback('#href="([^"]*)"#is', 'my_urlencode', $result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112372-solved-preg_replace-urlencode2/#findComment-577154 Share on other sites More sharing options...
Guest Posted June 29, 2008 Share Posted June 29, 2008 Thank you that did it completely. Quote Link to comment https://forums.phpfreaks.com/topic/112372-solved-preg_replace-urlencode2/#findComment-577432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.