ghostwalkz Posted January 1, 2009 Share Posted January 1, 2009 Hi all, It will be better to show you what I mean. Below is the 'string' (for example). We'll call it '$string1' What I want to do is Base64 encode everything between the href=" and the following quote (ie the url), not just once but throughout '$string1' Any Ideas? An exact code snippet would really be appreciated! snip-------- <link rel="shortcut icon" href="/cms/images/favicon.ico" /> <link href="/cms/templates/rt_versatility4_j15/css/template_css.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/menustyle4.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/style2.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/typography.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/system.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/general.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokslidestrip.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokmoomenu.css" rel="stylesheet" type="text/css" /> unsnip-------- Quote Link to comment https://forums.phpfreaks.com/topic/139115-solved-base64-encode-all-instances-of-a-string-within-a-string/ Share on other sites More sharing options...
sasa Posted January 1, 2009 Share Posted January 1, 2009 try <?php $test = '<link rel="shortcut icon" href="/cms/images/favicon.ico" /> <link href="/cms/templates/rt_versatility4_j15/css/template_css.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/menustyle4.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/style2.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/typography.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/system.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/general.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokslidestrip.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokmoomenu.css" rel="stylesheet" type="text/css" /> '; echo preg_replace_callback('/(\shref=")(.*?)(")/is', 'code', $test); function code($x){ return $x[1].base64_encode($x[2]).$x[3]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139115-solved-base64-encode-all-instances-of-a-string-within-a-string/#findComment-727590 Share on other sites More sharing options...
ghostwalkz Posted January 1, 2009 Author Share Posted January 1, 2009 Nope Sasa, I can't get this to work, thanks for your efforts, any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/139115-solved-base64-encode-all-instances-of-a-string-within-a-string/#findComment-727604 Share on other sites More sharing options...
DarkWater Posted January 1, 2009 Share Posted January 1, 2009 This works perfectly for me: <?php $test = '<link rel="shortcut icon" href="/cms/images/favicon.ico" /> <link href="/cms/templates/rt_versatility4_j15/css/template_css.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/menustyle4.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/style2.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/typography.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/system.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/general.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokslidestrip.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokmoomenu.css" rel="stylesheet" type="text/css" /> '; $test = preg_replace('/(?<=\bhref=")([^"]+)(?=")/e', 'base64_encode("$1");', $test); echo $test; ?> Quote Link to comment https://forums.phpfreaks.com/topic/139115-solved-base64-encode-all-instances-of-a-string-within-a-string/#findComment-727665 Share on other sites More sharing options...
ghostwalkz Posted January 1, 2009 Author Share Posted January 1, 2009 Sorry guys ya right, my mistake, thanks alot. ;-) Quote Link to comment https://forums.phpfreaks.com/topic/139115-solved-base64-encode-all-instances-of-a-string-within-a-string/#findComment-727669 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.