生成回复的图文数组

@param Article|Article[] $articles
@param array $search
@param array $replace
@return array
183907
public function generateReplyArticles(Article $articles, $search = [], $replace = [])
    {
        $wei = $this->wei;
        $data = [];
        foreach ($articles as $article) {
            // 如果指定了关键词,替换描述内容里的关键词
            if ($search) {
                $article['title'] = str_replace($search, $replace, $article['title']);
                $article['intro'] = str_replace($search, $replace, $article['intro']);
            }

            // 上传的封面图片,不以http开头
            if (!$wei->isStartsWith($article['thumb'], 'http')) {
                $article['thumb'] = $wei->request->getUrlFor($article['thumb']);
            }

            $data[] = [
                'title' => $article['title'],
                'description' => $articles->length() > 1 ? '' : $article['intro'],
                'picUrl' => $article['thumb'],
                'url' => $article->getFullUrl(),
            ];
        }

        return $data;
    }
10970
protected static function strReplaceOnce($search, $replace, $subject)
    {
        $firstChar = strpos($subject, $search);
        if (false !== $firstChar) {
            $beforeStr = substr($subject, 0, $firstChar);
            $afterStr = substr($subject, $firstChar + strlen($search));

            return $beforeStr.$replace.$afterStr;
        }

        return $subject;
    }
773112
protected function replaceIn($path, $search, $replace)
    {
        if ($this->output->isVerbose()) {
            $this->line("{$path} ...");
        }

        $this->filesystem->put($path, str_replace($search, $replace, $this->filesystem->get($path)));
    }
724917
function replaceString(content, search, replace) {
        var index = 0;

        do {
          index = content.indexOf(search, index);

          if (index !== -1) {
            content = content.substring(0, index) + replace + content.substr(index + search.length);
            index += replace.length - search.length + 1;
          }
        } while (index !== -1);

        return content;
      }
1299427
public function replace($search, $replace): FileDeclaration
    {
        $this->docComment->replace($search, $replace);
        $this->elements->replace($search, $replace);

        return $this;
    }
36405
public function setContent(array $content, $replace = false)
    {
        if ($replace) {
            $this->content = $content;
        } else {
            foreach ($content as $key => $value) {
                $this->content[$key] = $value;
            }
        }

        return $this;
    }
57127
private function replaceRecords(Collection $records, string $search, string $replace): int
    {
        $count = 0;
        $query = preg_quote($search, '/');

        foreach ($records as $record) {
            $old_record = $record->gedcom();
            $new_record = preg_replace('/(\n\d [A-Z0-9_]+ )' . $query . '/i', '$1' . $replace, $old_record);

            if ($new_record !== $old_record) {
                $record->updateRecord($new_record, true);
                $count++;
            }
        }

        return $count;
    }
485903
private function changePlacesUpdate(Tree $tree, string $search, string $replace): array
    {
        $individual_changes = DB::table('individuals')
            ->where('i_file', '=', $tree->id())
            ->whereContains('i_gedcom', $search)
            ->select(['individuals.*'])
            ->get()
            ->map(Individual::rowMapper());

        $family_changes = DB::table('families')
            ->where('f_file', '=', $tree->id())
            ->whereContains('f_gedcom', $search)
            ->select(['families.*'])
            ->get()
            ->map(Family::rowMapper());

        return $individual_changes
            ->merge($family_changes)
            ->mapWithKeys(static function (GedcomRecord $record) use ($search, $replace): array {
                $changes = [];

                foreach ($record->facts() as $fact) {
                    $old_place = $fact->attribute('PLAC');
                    if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
                        $new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
                        $changes[$old_place] = $new_place;
                        $gedcom              = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->gedcom());
                        $record->updateFact($fact->id(), $gedcom, false);
                    }
                }

                return $changes;
            })
            ->sort()
            ->all();
    }
888713
protected function filterArrayStrings($array, $search, $replace)
    {
        $return = array();
        foreach ((array)$array as $key => $value) {
            $key = str_replace($search, $replace, $key);
            $value = is_array($value)
                ? $this->filterArrayStrings($value, $search, $replace)
                : str_replace($search, $replace, $value);

            $return[$key] = $value;
        }

        return $return;
    }
115167
public static function deepReplace($ini, $search, $replace)
    {
        if (is_object($ini)) {
            foreach ($ini as $key => &$value) {
                $value = self::deepReplace($value, $search, $replace);
            }
        } else {
            $ini = str_replace($search, $replace, $ini);
            return $ini;
        }
        return $ini;
    }
100033
function replace($search,$replace){
		$this->_String = str_replace($search,$replace,$this->_String);
	}
85104
public function replace_all_text($table, database_column_info $column, $search, $replace) {
        if (!$this->replace_all_text_supported()) {
            return;
        }

        // NOTE: override this methods if following standard compliant SQL
        //       does not work for your driver.

        // Enclose the column name by the proper quotes if it's a reserved word.
        $columnname = $this->get_manager()->generator->getEncQuoted($column->name);

        $searchsql = $this->sql_like($columnname, '?');
        $searchparam = '%'.$this->sql_like_escape($search).'%';

        $sql = "UPDATE {".$table."}
                       SET $columnname = REPLACE($columnname, ?, ?)
                     WHERE $searchsql";

        if ($column->meta_type === 'X') {
            $this->execute($sql, array($search, $replace, $searchparam));

        } else if ($column->meta_type === 'C') {
            if (core_text::strlen($search) < core_text::strlen($replace)) {
                $colsize = $column->max_length;
                $sql = "UPDATE {".$table."}
                       SET $columnname = " . $this->sql_substr("REPLACE(" . $columnname . ", ?, ?)", 1, $colsize) . "
                     WHERE $searchsql";
            }
            $this->execute($sql, array($search, $replace, $searchparam));
        }
    }
716721
public function swapTablePrefix($search, $replace)
    {
        $Sql = empty($this->sqlFinalStatement) ? $this->sqlStatement : $this->sqlFinalStatement;

        $this->sqlFinalStatement = preg_replace('/(\W)' . $search . '(\S+?)/', '\\1' . $replace . '\\2', $Sql);

        return $this;
    }
95456
protected function replaceUnEscaped($search, $replace, $subject)
    {
        $search = (array)$search;
        $replace = (array)$replace;

        $patterns = [];

        foreach ($search as $i => $pattern) {
            $patterns[] = "/(?<!\\\\)$pattern/u";
        }

        return preg_replace($patterns, $replace, $subject);
    }
1370732
public static function strIreplace($search, $replace, $str, $count = null, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if (!is_array($search)) {
            $slen = strlen($search);

            if ($slen == 0) {
                return $str;
            }

            $lendif = strlen($replace) - strlen($search);
            $search = static::strtolower($search, $encoding);
            $search = preg_quote($search, '/');
            $lstr = static::strtolower($str, $encoding);
            $i = 0;
            $matched = 0;

            while (preg_match('/(.*)' . $search . '/Us', $lstr, $matches)) {
                if ($count !== null && $i === $count) {
                    break;
                }

                $mlen = strlen($matches[0]);
                $lstr = substr($lstr, $mlen);

                $str = substr_replace($str, $replace, $matched + strlen($matches[1]), $slen);
                $matched += $mlen + $lendif;
                $i++;
            }

            return $str;
        } else {
            $keys = array_keys($search);

            foreach ($keys as $k) {
                if (is_array($replace)) {
                    if (array_key_exists($k, $replace)) {
                        $str = static::strIreplace($search[$k], $replace[$k], $str, $count, $encoding);
                    } else {
                        $str = static::strIreplace($search[$k], '', $str, $count, $encoding);
                    }
                } else {
                    $str = static::strIreplace($search[$k], $replace, $str, $count, $encoding);
                }
            }

            return $str;
        }
    }
992418
public function send(WeChatApp $app, $search = [], $replace = [])
    {
        if ($this['type'] == 'text') {
            if ($search) {
                $this['content'] = str_replace($search, $replace, $this['content']);
            }
            // 直接返回content字段,由weChatApp服务构造XML.如果内容为空,weChatApp会自动输入空字符串,这样符合微信的要求
            return $this['content'];
        } elseif ($this['type'] == 'article') {
            return $app->sendArticle($this->toArticleArray($search, $replace));
        } else {
            $ret = wei()->wechatMedia->findOrCreateByPath($this['replies']['image']['url']);
            return $app->send('image', ['Image' => ['MediaId' => $ret['data']['wechatMediaId']]]);
        }
    }
144229
public static String replace(String str, String[] search, String[] replace) {
        if (str == null || search == null || replace == null) {
            return str;
        }
        StringBuilder sb = new StringBuilder(str);
        int loop = (search.length <= replace.length) ? search.length : replace.length;
        int start = 0;
        int end;
        int searchLen;
        int replaceLen;
        for (int i = 0; i < loop; i++) {
            if (search[i] == null || replace[i] == null) {
                continue;
            }
            searchLen = search[i].length();
            replaceLen = replace[i].length();
            while (true) {
                if (sb.length() == 0) {
                    break;
                }
                start = sb.indexOf(search[i], start + replaceLen);
                if (start == -1) {
                    break;
                }
                end = start + searchLen;
                sb.replace(start, end, replace[i]);
            }
        }
        return sb.toString();
    }