Esempio n. 1
0
Array f_get_meta_tags(CStrRef filename, bool use_include_path /* = false */) {
  String f = f_file_get_contents(filename);

  Variant matches;
  f_preg_match_all("/<meta\\s+name=\"(.*?)\"\\s+content=\"(.*?)\".*?>/s",
                   f, ref(matches), k_PREG_SET_ORDER);

  Array ret = Array::Create();
  for (ArrayIter iter(matches); iter; ++iter) {
    Array pair = iter.second();
    ret.set(normalize_variable_name(pair[1].toString()), pair[2]);
  }
  return ret;
}
Esempio n. 2
0
bool TestExtPreg::test_preg_match_all() {
  Variant matches;

  f_preg_match_all("/\\(?  (\\d{3})?  \\)?  (?(1)  [\\-\\s] ) \\d{3}-\\d{4}/x",
                   "Call 555-1212 or 1-800-555-1212", ref(matches));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => 555-1212\n"
     "            [1] => 800-555-1212\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => \n"
     "            [1] => 800\n"
     "        )\n"
     "\n"
     ")\n");

  // The \\2 is an example of backreferencing. This tells pcre that
  // it must match the second set of parentheses in the regular expression
  // itself, which would be the ([\w]+) in this case. The extra backslash is
  // required because the string is in double quotes.
  String html = "<b>bold text</b><a href=howdy.html>click me</a>";
  f_preg_match_all("/(<([\\w]+)[^>]*>)(.*)(<\\/\\2>)/", html, ref(matches),
                   k_PREG_SET_ORDER);
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => <b>bold text</b>\n"
     "            [1] => <b>\n"
     "            [2] => b\n"
     "            [3] => bold text\n"
     "            [4] => </b>\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => <a href=howdy.html>click me</a>\n"
     "            [1] => <a href=howdy.html>\n"
     "            [2] => a\n"
     "            [3] => click me\n"
     "            [4] => </a>\n"
     "        )\n"
     "\n"
     ")\n");

  String str = "a: 1\nb: 2\nc: 3\n";
  f_preg_match_all("/(?<name>\\w+): (?<digit>\\d+)/", str, ref(matches));
  VS(f_print_r(matches, true),
     "Array\n"
     "(\n"
     "    [0] => Array\n"
     "        (\n"
     "            [0] => a: 1\n"
     "            [1] => b: 2\n"
     "            [2] => c: 3\n"
     "        )\n"
     "\n"
     "    [name] => Array\n"
     "        (\n"
     "            [0] => a\n"
     "            [1] => b\n"
     "            [2] => c\n"
     "        )\n"
     "\n"
     "    [1] => Array\n"
     "        (\n"
     "            [0] => a\n"
     "            [1] => b\n"
     "            [2] => c\n"
     "        )\n"
     "\n"
     "    [digit] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => 2\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     "    [2] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => 2\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     ")\n");

  return Count(true);
}