Asked  7 Months ago    Answers:  5   Viewed   30 times

I'm not familiar with the how regular expressions treat hexadecimal, anyone knows?

 Answers

85

The following does the trick:

$str = "some ??????????";

echo preg_replace('/[x{00ff}-x{ffff}]/u', '*', $str);
// some **********

echo preg_replace('/[^x{00ff}-x{ffff}]/u', '*', $str);
// *****??????????

The important thing is the u-modifier (see here):

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

And here a short description why uFFFF is not working in PHP:

Perl and PCRE do not support the uFFFF syntax. They use x{FFFF} instead. You can omit leading zeros in the hexadecimal number between the curly braces. Since x by itself is not a valid regex token, x{1234} can never be confused to match x 1234 times. It always matches the Unicode code point U+1234. x{1234}{5678} will try to match code point U+1234 exactly 5678 times.

Wednesday, March 31, 2021
 
Ula
answered 7 Months ago
Ula
15

This will work only for non-nested parentheses:

    $regex = <<<HERE
    /  "  ( (?:[^"\\]++|\\.)*+ ) "
     | '  ( (?:[^'\\]++|\\.)*+ ) '
     | ( ( [^)]*                  ) )
     | [s,]+
    /x
    HERE;

    $tags = preg_split($regex, $str, -1,
                         PREG_SPLIT_NO_EMPTY
                       | PREG_SPLIT_DELIM_CAPTURE);

The ++ and *+ will consume as much as they can and give nothing back for backtracking. This technique is described in perlre(1) as the most efficient way to do this kind of matching.

Wednesday, March 31, 2021
 
KingCrunch
answered 7 Months ago
52

The standard disclaimer applies: Parsing HTML with regular expressions is not ideal. Success depends on the well-formedness of the input on a character-by-character level. If you cannot guarantee this, the regex will fail to do the Right Thing at some point.

Having said that:

<ab[^>]*>(.*?)</a>   // match group one will contain the link text
Saturday, May 29, 2021
 
lewiguez
answered 5 Months ago
68

Use a loop like so

$data = file('website/files/myfolder/file.html');
for ($i = 23; $i <= 116; $i++) {
    echo $data[$i];
}
  • http://php.net/manual/en/control-structures.for.php

Or you could splice the data:

$data = file('website/files/myfolder/file.html');
echo implode(PHP_EOL, array_splice($data, 23, 116 - 23));
  • http://php.net/manual/en/function.array-splice.php
  • http://php.net/manual/en/function.implode.php
Saturday, May 29, 2021
 
Santi
answered 5 Months ago
29

I would think that calling startForeground() again with the same unique ID and a Notification with the new information would work, though I have not tried this scenario.

Update: Based on the comments, you should use NotifcationManager to update the notification and your service continues to stay in the foreground mode. Take a look at the answer below.

Sunday, June 27, 2021
 
muffe
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :