I have a series of urls in a web doc, something like this:
<a href="somepage.php?x=some_document.htm">click here</a>
What I want to do is replace the bold piece:
<a href="somepage.php?x=some_document.htm">click here</a>
.. with some sort of encrypted variation (lets just say base64_encoding) .. something like this:
for each match, turn it into base64_encode(match)
Notes:
1.the phrase href="somepage.php?x= will always precede the phrase.
2.a double-quote (") will always follow the phrase.
I am not a regex guru -- but I know some of you are. Any easy way to do this?
UPDATE:
I solved this by using a modified version of what Chris submitted, here it is:
function encrypt_param( $in_matches ) {
return 'href="somepage.php?x=' . base64_encode( $in_matches[1] ) . '"';
}
$webdoc = preg_replace_callback( '/href="somepage.php\?x=([^"]+)"/',
'encrypt_param',
$webdoc );