Replace url in content

@param string $content
@param string $oldPrefix
@param string $newPrefix

@return string Content with replaced urls
191855
public static function replaceUrl($content, $oldPrefix, $newPrefix)
    {
        $replacedUrl = preg_replace(
            '#(.*?)/' . preg_quote($oldPrefix, '#') . '(.*?)#',
            '$1/' . $newPrefix . '$2',
            $content
        );
    
        return $replacedUrl;
    }
254833
public function parseNoTemplate($content) {
        $this->_content = $content;
        $this->_parseDebugStart();
        $this->_parseExtend();
        $this->_parseInclude();
        $this->_parsePath();
        $this->_parseGravatar();
        $this->_parseAsset();
        $this->_parseUrl();
        $this->_parsePhp();
        $this->_parseLang();
        $this->_parseForeach();
        $this->_parseFor();
        $this->_parseVar();
        $this->_parseVarFunc();
        $this->_parseCondition();
        $this->_parseFunction();
        $this->_parseException();
        $this->_parseMinify();
        $this->_parseDebugEnd();

        return $this->_content;
    }
960838
public Text replaceWholeText(String content) throws DOMException {
	Text oldText = text;
	Document doc = XMLUtil.getDocument(text);
	Text newText = doc.createTextNode(content);
	Node parent = oldText.getParentNode();
	parent.replaceChild(XMLCaster.toRawNode(newText), XMLCaster.toRawNode(oldText));
	return oldText;
    }
2646
public function replace($key, $content, $expiry = 0)
    {
        if (!$this->get($key)) {
            return false;
        }

        return $this->set($key, $content, $expiry);
    }
1207856
protected function _replaceCssUrl($file, $content)
    {
        $path = dirname(substr($this->alias->resolve($file), strlen($this->alias->get('@public'))));

        return preg_replace_callback('#url\((.+?)\)#', function ($match) use ($path) {
            $url = trim($match[1], '\'"');
            if ($url === '' || strpos($url, '//') !== false) {
                return $match[0];
            }

            if ($url[0] !== '/') {
                while (strpos($url, '../') === 0) {
                    $path = dirname($path);
                    $url = substr($url, 3);
                }

                $url = rtrim($path, '/\\') . '/' . $url;
            }
            return sprintf('url("%s")', $this->alias->get('@asset') . $url);
        }, $content);
    }
1189606
private function insertOrReplaceTag($content, $search, $replace)
    {
        $newContent =  null;

        $regexSearch = "/(\<$search\>\<\!\[CDATA\[([0-9.])+\]\]\>\<\/$search\>)/";
        if(preg_match($regexSearch, $content)) {
            $newContent = preg_replace($regexSearch, $replace, $content);
        }
        else {
            $newContent = $content . $replace;

        }

        return $newContent;
    }
344618
function modifyContent(&$content) {
    	//Remove comments
		$content = preg_replace('#\/\*(?!\*\/)(.*?)\*\/#si', '', $content);
		$content = str_replace('<!--', '', $content);
		$content = str_replace('-->', '', $content);
		$content = trim($content);

		if (!isset($this->url)) return $content;
		$this->regex = array();
		$this->replace = array();

		$pathinfo = parse_url($this->url);

		$sorceurl = $pathinfo['scheme'] . '://' . $pathinfo['host'] . '/';

		$sorcepath = explode('/', $pathinfo['path']);
		array_shift($sorcepath);
		array_pop($sorcepath);

		$sorcepathoriginal = $sorcepath;

		while(count($sorcepath)) {
			$temp = $sorcepathoriginal;
			$path = '';
			foreach($sorcepath as $values) {
				$path .= '\.\.\/';
				array_pop($temp);
			}

			$turl = $sorceurl;
			if (count($temp)) {
				$turl .= implode('/', $temp) . '/';
			}
			$this->regex[] = '#' . $path . '#iSs';
			$this->replace[] = $turl;
			array_pop($sorcepath);
		}

		$this->thisUrl = $sorceurl . implode('/', $sorcepathoriginal) . '/';

		$this->regex[] = '#\.\/#is';
		$this->replace[] = $sorceurl . implode('/', $sorcepathoriginal) . '/';

		$this->regex[] = '#url\(([^"\'\)]*)\)#is';
		$this->replace[] = 'url("$1")';

		$this->regex[] = '#url\(["\']/([^"\']*)["\']\)#Sis';
		$this->replace[] = 'url("' . $sorceurl . '$1")';

		$this->regex[] = '#url\(["\'](?!\w{0,10}://)([^"\']*)["\']\)#Sis';
		$this->replace[] = 'url("' . $sorceurl . implode('/', $sorcepathoriginal) . '/$1")';

		$regexall = $this->regex;
		$replaceall = $this->replace;

		$content = preg_replace($regexall, $replaceall, $content);

		if (preg_match_all('#@import.*?[\'"]([^\'"]*)[\'"].*?;#Sis', $content, $imports)) {
			foreach ($imports[1] as $key => $import) {
				$cssparser = new Css($this->prefix);
				$cssparser->ParseUrl($import);
				$temp = $cssparser->GetCSS();

				$content = str_replace($imports[0][$key], '', $content );

				$content = $temp . $content;
			}
		}
		return $content;
	}
593084
protected function replaceLinkTargets($processedContent)
    {
        $noOpenerString = $this->fusionValue('setNoOpener') ? ' rel="noopener"' : '';
        $externalLinkTarget = trim($this->fusionValue('externalLinkTarget'));
        $resourceLinkTarget = trim($this->fusionValue('resourceLinkTarget'));
        if ($externalLinkTarget === '' && $resourceLinkTarget === '') {
            return $processedContent;
        }
        $controllerContext = $this->runtime->getControllerContext();
        $host = $controllerContext->getRequest()->getHttpRequest()->getUri()->getHost();
        $processedContent = preg_replace_callback(
            '~<a .*?href="(.*?)".*?>~i',
            function ($matches) use ($externalLinkTarget, $resourceLinkTarget, $host, $noOpenerString) {
                list($linkText, $linkHref) = $matches;
                $uriHost = parse_url($linkHref, PHP_URL_HOST);
                $target = null;
                if ($externalLinkTarget !== '' && is_string($uriHost) && $uriHost !== $host) {
                    $target = $externalLinkTarget;
                }
                if ($resourceLinkTarget !== '' && strpos($linkHref, '_Resources') !== false) {
                    $target = $resourceLinkTarget;
                }
                if ($target === null) {
                    return $linkText;
                }
                if (preg_match_all('~target="(.*?)~i', $linkText, $targetMatches)) {
                    return preg_replace('/target=".*?"/', sprintf('target="%s"%s', $target, $target === '_blank' ? $noOpenerString : ''), $linkText);
                }
                return str_replace('<a', sprintf('<a target="%s"%s', $target, $target === '_blank' ? $noOpenerString : ''), $linkText);
            },
            $processedContent
        );
        return $processedContent;
    }
814316
public function put($content)
    {
        $this->content = SerializationHelper::serialize($content);
        $url = $this->url;
        if (!empty($this->replaceParams)) {
            $url = self::buildUri($url, $this->replaceParams);
        }
        $this->adapter->setResponseTimeout($this->getResponseTimeout());
        $this->adapter->setConnectTimeout($this->getConnectTimeout());

        return $this->adapter->put(
            $url,
            array(
                self::HEADERS => $this->headers,
                self::CONTENT => $this->content,
            )
        );
    }
380112
function replace($old, $new, $limit = null) {
		$old = self::toNativeString ( $old );
		$new = self::toNativeString ( $new );
		$oldLength = strlen ( $old );
		$newLength = strlen ( $new );
		$string = $this->string;
		$offset = 0;
		for ($i = 0; $limit === null || $i < $limit; $i ++) {
			$position = strpos ( $string, $old, $offset );
			if ($position === false) {
				break;
			}
			$string = substr_replace ( $string, $new, $position, $oldLength );
			$offset += $position + $newLength;
		}
		return new self ( $string );
	}
1254407
protected function formatContent($content)
    {
        $searches = array(
            '{{filename}}',
            '{{namespace}}',
            '{{className}}',
        );

        $replaces = array(
            $this->data['filename'],
            $this->data['namespace'],
            $this->data['className'],
        );

        return str_replace($searches, $replaces, $content);
    }
567228
public function replaceLinks($string)
    {
        preg_match_all('/(\[content_url\](.*?)\[\/content_url\]|\[content_url\](.*?)\[\\\\\/content_url\])/', $string, $matches);

        if (!count($matches)) {
            return $string;
        }

        if (!empty($matches[3][0])) {
            $matches[1] = $matches[3];
        } elseif (!empty($matches[2][0])) {
            $matches[1] = $matches[2];
        }

        /** @var ContentInterface[] $contents */
        $contents = $this->contentManager->getRepository()->findByIds($matches[1]);
        $array = [];
        foreach ($contents as $content) {
            $array[$content->getId()] = $content;
        }

        foreach ($matches[0] as $key => $match) {
            if (isset($array[$matches[1][$key]])) {
                $content = $array[$matches[1][$key]];

                $url = $this->router->generate('_content', ['slug' => $content->getSlug()]);
            } else {
                $url = $this->router->generate('_content', ['slug' => '404']);
            }

            $string = str_replace($match, $url, $string);
        }

        return $string;
    }
125920
protected static function formatUsesPrefix($new, $old)
    {
        if (isset($new['namespace']) && isset($old['namespace'])) {
            return trim(array_get($old, 'namespace'), '\\') . '\\' . trim($new['namespace'], '\\');
        } elseif (isset($new['namespace'])) {
            return trim($new['namespace'], '\\');
        }
        
        return array_get($old, 'namespace');
    }
719802
private function replaceModelName($content)
    {
        $newContent = '';
        $content = str_replace('new %modelName%', 'new '.$this->model, $content);
        $content = str_replace('%StaticModelName%', $this->model, $content);
        $content = str_replace('new %StaticModelName%()', $this->model, $content);
        $newContent = str_replace('%modelName%', Inflector::tabilize($this->model), $content);

        return $newContent;
    }
529642
public function replaceInFile($old, $new, $append = 0)
    {
        $contents = $this->previous;
        $replaceWith = preg_replace("~$old\n?~", "$new\n", $contents);

        file_put_contents($this->getPath(), $replaceWith, $append);

        return $this;
    }
1043759
public function replaceUncloneable( $content, $ids = [] ) {
		$pattern = get_shortcode_regex( [ self::SHORTCODE ] );
		$callback = function ( $shortcode ) use ( $ids ) {
			$warning = __( 'The original version of this chapter contained H5P content. You may want to remove or replace this element.', 'pressbooks' );
			if ( empty( $ids ) ) {
				return $warning;
			} else {
				$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
				if ( is_array( $shortcode_attrs ) && isset( $shortcode_attrs['id'] ) ) {
					// Remove quotes, return just the integer
					$my_id = $shortcode_attrs['id'];
					$my_id = trim( $my_id, "'" );
					$my_id = trim( $my_id, '"' );
					$my_id = str_replace( '&quot;', '', $my_id );
					if ( in_array( $my_id, (array) $ids, false ) ) { // @codingStandardsIgnoreLine
						return $warning;
					}
				}
			}
			return $shortcode[0];
		};
		$content = preg_replace_callback(
			"/$pattern/",
			$callback,
			$content
		);
		return $content;
	}
468061
public static function replaceTag($tag, $replacement, $content, $attributes = null)
        {
            $content = preg_replace("/<{$tag}.*?>/", "<{$replacement} {$attributes}>", $content);
            $content = preg_replace("/<\/{$tag}>/", "</{$replacement}>", $content);
            return $content;
        }