Esempio n. 1
0
bool TestExtString::test_str_replace() {
  {
    VS(f_str_replace("%body%", "black", "<body text='%body%'>"),
       "<body text='black'>");
  }
  {
    Array vowels;
    vowels.append("a");
    vowels.append("e");
    vowels.append("i");
    vowels.append("o");
    vowels.append("u");
    vowels.append("A");
    vowels.append("E");
    vowels.append("I");
    vowels.append("O");
    vowels.append("U");
    VS(f_str_replace(vowels, "", "Hello World of PHP"), "Hll Wrld f PHP");
  }
  {
    String phrase  = "You should eat fruits, vegetables, and fiber every day.";
    Array healthy = CREATE_VECTOR3("fruits", "vegetables", "fiber");
    Array yummy   = CREATE_VECTOR3("pizza", "beer", "ice cream");
    VS(f_str_replace(healthy, yummy, phrase),
       "You should eat pizza, beer, and ice cream every day.");
  }
  {
    Variant count;
    Variant str = f_str_replace("ll", "", "good golly miss molly!",
                                ref(count));
    VS(count, 2);
  }
  {
    Array letters = CREATE_VECTOR2("a", "p");
    Array fruit = CREATE_VECTOR2("apple", "pear");
    String text = "a p";
    VS(f_str_replace(letters, fruit, text), "apearpearle pear");
  }

  return Count(true);
}
Esempio n. 2
0
bool TestExtMb::test_mb_ereg_replace() {
  {
    String str = "This is a test";
    VS(f_str_replace(" is", " was", str), "This was a test");
    VS(f_mb_ereg_replace("( )is", "\\1was", str), "This was a test");
    VS(f_mb_ereg_replace("(( )is)", "\\2was", str), "This was a test");
  }
  {
    int num = 4;
    String str = "This string has four words.";
    str = f_mb_ereg_replace("four", num, str);
    VS(str, "This string has 4 words.");
  }
  {
    String test = "http://test.com/test";
    test = f_mb_ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
                             "<a href=\"\\0\">\\0</a>", test);
    VS(test, "<a href=\"http://test.com/test\">http://test.com/test</a>");
  }
  return Count(true);
}