473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

base64 encoding a replace string

I've got the example below to set up phpOpenTracker to log exit URL's
but I'm having trouble getting it to work. I have played with the
quotes and changed the \\2 to $3 and got the url in there but I can't
get it to base64 encode it.

I'm new to PHP and any help on getting the encoding to work would be
appreciated.

<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}

// start output-buffering
ob_start('encode_exit_urls');

// main code of your script
?>
--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk
Jul 17 '05 #1
5 25970
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
I'm new to PHP and any help on getting the encoding to work would be
appreciated.

<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}


You'll have to use preg_replace_callback if you want to "do things" with
the backreferences.

--

Daniel Tryba

Jul 17 '05 #2
On Thu, 23 Oct 2003 12:05:13 +0000 (UTC), Daniel Tryba wrote:
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
I'm new to PHP and any help on getting the encoding to work would be
appreciated.

<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}


You'll have to use preg_replace_callback if you want to "do things" with
the backreferences.


I'm putting this before any output from HTML and it is changing the URL
but not doing a base64 encode on it. Should the base64 encode be done
when it does the replacement or is that something done by the browser
when it goes to the link?

I've tried <a href="exit.php?url=.base64_encode('the_link_url'). ">
directly in the link so I don't think the browser does it.

The problem is that I have some links to Google articles and unless I
encode them exit.php sees them as parameters to it and not to Google.

I've given up on this for the site, I'm base64 encoding the URL and
pasting it into the href, but I'm interested in how this is supposed to
work. I can't find any info on base64_encode being embedded in a string
in the PHP manual.

--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk
Jul 17 '05 #3
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}
You'll have to use preg_replace_callback if you want to "do things" with
the backreferences.

[snip] I've given up on this for the site, I'm base64 encoding the URL and
pasting it into the href, but I'm interested in how this is supposed to
work. I can't find any info on base64_encode being embedded in a string
in the PHP manual.


Have you actually read my posting? You have to use preg_replace_callback()
http://php.net/preg_replace_callback instead of preg_replace()

It takes a funtion instead of a string. That function should return the
a/href with the backreference 2 base64 encoded.

--

Daniel Tryba

Jul 17 '05 #4
On Fri, 24 Oct 2003 11:39:15 +0000 (UTC), Daniel Tryba wrote:
<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}

You'll have to use preg_replace_callback if you want to "do things" with
the backreferences.

[snip]
I've given up on this for the site, I'm base64 encoding the URL and
pasting it into the href, but I'm interested in how this is supposed to
work. I can't find any info on base64_encode being embedded in a string
in the PHP manual.


Have you actually read my posting? You have to use preg_replace_callback()
http://php.net/preg_replace_callback instead of preg_replace()

It takes a funtion instead of a string. That function should return the
a/href with the backreference 2 base64 encoded.


I did read your posting Daniel. I looked up preg_replace_callback but I
didn't understand how to create a function that could replace the
a/href base64 encoded.

Having had another look I think the light is beginning to dawn. If I
understand it correctly all I have to do with the function is do a
base64 encode on the third subpattern match, add the bits I want on and
return it.

I don't have output buffering on the host so I'm having to turn it on
to create a session cookie and then turn it off. This works fine with
Apache here but inserts a blank line with IIS on the host when I turn
it off and flush, this isn't helping with the formatting :-)

Thanks for your help and patience.

--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk
Jul 17 '05 #5
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
Have you actually read my posting? You have to use preg_replace_callback()
http://php.net/preg_replace_callback instead of preg_replace()

It takes a funtion instead of a string. That function should return the
a/href with the backreference 2 base64 encoded.
I did read your posting Daniel. I looked up preg_replace_callback but I
didn't understand how to create a function that could replace the
a/href base64 encoded.

Having had another look I think the light is beginning to dawn. If I
understand it correctly all I have to do with the function is do a
base64 encode on the third subpattern match, add the bits I want on and
return it.


:) The online manual sometimes needs to be read more than once...
I don't have output buffering on the host so I'm having to turn it on
to create a session cookie and then turn it off. This works fine with
Apache here but inserts a blank line with IIS on the host when I turn
it off and flush, this isn't helping with the formatting :-)


Hmmm, have you taken a look in the bug database? Sounds weird.

--

Daniel Tryba

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mvdevnull | last post by:
hey all currently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
2
by: kevin | last post by:
DISCLAIMER: I know what the words mean (i.e. by definition), but I in know way pretend to understand the specifics of either, therefore I may need a basic primer before I can accomplish this task,...
3
by: mm | last post by:
Hello everyone, I have an asp.net application executing under .net framework 1.1 that sends a base64 encoded string token to a remote server running weblogic application server. for some odd...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
5
by: Jay | last post by:
I have bean trying to get my head around reading .GIF files from base64 strings, Basically I need to specify a filename and convert it to base64 then I can copy/past the string to wear I want it....
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
13
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or...
10
by: pycraze | last post by:
Hi , I am currently trying to implement base64 encoding and decoding scheme in C . Python has a module , base64 , that will do the encoding and decoding with ease . I am aware of OpenSSL having...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.