php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49699 str_rot13 in combination with preg_replace doesnt work
Submitted: 2009-09-28 15:37 UTC Modified: 2009-09-28 16:06 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: william at 1moment dot nl Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3SVN-2009-09-28 (SVN) OS: UNIX
Private report: No CVE-ID: None
 [2009-09-28 15:37 UTC] william at 1moment dot nl
Description:
------------
When using str_rot13 within a preg_replace context the string won't be rotated, but stays the same.

Reproduce code:
---------------
function addRotation($string) {
	//return md5($string); // This works
	return str_rot13($string); // This won't work
}

$output = '<html><head><head><body><a href="mailto:example@example.com">this is a test</a></body></html>';
$parsed = preg_replace("/\"mailto:([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z.]{2,4})\"/", "\"folder/?e=" .  addRotation('\\1')  . "+" .  addRotation('\\2') . "+" . addRotation('\\3') ."\" rel=\"nofollow\" target=\"_blank\"", $output);

echo $parsed;

Expected result:
----------------
<html><head><head><body><a href="/folder/?e=rknzcyr@rknzcyr.com">this is a test</a></body></html>

Actual result:
--------------
<html><head><head><body><a href="/folder/?e=example@example.com">this is a test</a></body></html>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-28 15:39 UTC] william at 1moment dot nl
Sorry the expected result should be:

<a href="/folder/?e=rknzcyr+rknzcyr+com">

and the actual result should be:

<a href="/folder/?e=example+example+com">
 [2009-09-28 16:06 UTC] jani@php.net
Your code is buggy. RTFM and also try this code:

<?php

function addRotation($string) {
        return str_rot13($string);
}

$output = 'foo';
$parsed = preg_replace("/(foo)/e", "addRotation('\\1')", $output);
var_dump($parsed);

?>

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 01:01:33 2024 UTC