Jump to content

[SOLVED] Base64 Encode all instances of a $string within a $string


ghostwalkz

Recommended Posts

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--------

Link to comment
Share on other sites

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];
}
?>

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.