hiphop-php /hphp/test/slow/ext_preg/ext_preg_e.php

Language PHP Lines 58
MD5 Hash fe97c939cf89a7a4824783f5b46fce3d Estimated Cost $1,065 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

function test_preg_rep($a,$b,$c) {
  return strtoupper($c).$a;
}

function test_preg_replace() {
  var_dump(preg_replace(
    "/no match/e",
    "strtoupper(\"$1\")",
    "doesn't match"
  ));

  var_dump(preg_replace(
    "/no match/e",
    "bad_func(\"$1\")",
    "doesn't match"
  ));

  var_dump(preg_replace(
    "/(<\\/?\\w+[^>]*>)/e",
    "strtoupper(\"$1\")",
    "<html><body></body></html>"
  ));

  var_dump(preg_replace(
    "/#([A-Fa-f0-9]{3,6});/e",
    "strtolower(\"#\\1;\");",
    "#AAAA;"
  ));

  var_dump(preg_replace(
    "/rgb\\(([0-9]{1,3}), ([0-9]{1,3}), ([0-9]{1,3})\\)/e",
    "sprintf(\"%02x%02x%02x\", \"\\1\", \"\\2\", \"\\3\")",
    "rgb(13, 14, 15)"
  ));

  var_dump(preg_replace(
    "/(a*)(b*)/e",
    "test_preg_rep(\"\\1\",\"smu\\\"rf\",\"\\2\")",
    "aaabbbblahblahaabbbababab"
  ));

  var_dump(preg_replace_callback(
    "/a/e",
    "test_preg_rep",
    "a"
  ));

  var_dump(preg_replace(
    "/(a)/e",
    "str_repeat('$1', 500)",
    "aaaaaaaaaaaaaaaaaaaa"
  ));
}

test_preg_replace();
Back to Top