fork(5) download
  1. <?php
  2.  
  3. $rests = array();
  4. $re = '~\b(https?://)www\.myweb\.com/(\S+)~';
  5. $str = "Some text https://w...content-available-to-author-only...b.com/page/cat/323123442321-rghe432 and then another https://w...content-available-to-author-only...e.com/fsdhjss/erwr";
  6. echo $result = preg_replace_callback($re, function ($m) use (&$rests) {
  7. array_push($rests, $m[2]);
  8. return $m[1] . "embed.myweb.com/" . $m[2];
  9. }, $str) . PHP_EOL;
  10. print_r($rests);
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
Some text https://e...content-available-to-author-only...b.com/page/cat/323123442321-rghe432 and then another https://w...content-available-to-author-only...e.com/fsdhjss/erwr
Array
(
    [0] => page/cat/323123442321-rghe432
)