本文整理汇总了PHP中w3_preg_quote函数的典型用法代码示例。如果您正苦于以下问题:PHP w3_preg_quote函数的具体用法?PHP w3_preg_quote怎么用?PHP w3_preg_quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了w3_preg_quote函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove_scripts
/**
* Remove script tags from the source
*
* @param string $content
* @param array $files
* @return void
*/
function remove_scripts(&$content, $files)
{
$regexps = array();
$home_url_regexp = w3_get_home_url_regexp();
$path = '';
if (w3_is_network() && !w3_is_subdomain_install()) {
$path = ltrim(w3_get_home_path(), '/');
}
foreach ($files as $file) {
if ($path && strpos($file, $path) === 0) {
$file = substr($file, strlen($path));
}
$this->replaced_scripts[] = $file;
if (w3_is_url($file) && !preg_match('~' . $home_url_regexp . '~i', $file)) {
// external JS files
$regexps[] = w3_preg_quote($file);
} else {
// local JS files
$file = ltrim($file, '/');
if (ltrim(w3_get_site_path(), '/') && strpos($file, ltrim(w3_get_site_path(), '/')) === 0) {
$file = str_replace(ltrim(w3_get_site_path(), '/'), '', $file);
}
$file = ltrim(preg_replace('~' . $home_url_regexp . '~i', '', $file), '/\\');
$regexps[] = '(' . $home_url_regexp . ')?/?' . w3_preg_quote($file);
}
}
foreach ($regexps as $regexp) {
$content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~Uis', '', $content);
}
}
示例2: generate_rules_no404wp_nginx
/**
* Generate rules related to prevent for media 404 error by WP
*
* @return string
*/
function generate_rules_no404wp_nginx()
{
$cssjs_types = $this->_get_cssjs_types();
$html_types = $this->_get_html_types();
$other_types = $this->_get_other_types();
$extensions = array_merge(array_keys($cssjs_types), array_keys($html_types), array_keys($other_types));
$permalink_structure = get_option('permalink_structure');
$permalink_structure_ext = ltrim(strrchr($permalink_structure, '.'), '.');
if ($permalink_structure_ext != '') {
foreach ($extensions as $index => $extension) {
if (strstr($extension, $permalink_structure_ext) !== false) {
$extensions[$index] = preg_replace('~\\|?' . w3_preg_quote($permalink_structure_ext) . '\\|?~', '', $extension);
}
}
}
$exceptions = $this->_config->get_array('browsercache.no404wp.exceptions');
$rules = '';
$rules .= W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP . "\n";
$rules .= "if (-f \$request_filename) {\n";
$rules .= " break;\n";
$rules .= "}\n";
$rules .= "if (-d \$request_filename) {\n";
$rules .= " break;\n";
$rules .= "}\n";
if (count($exceptions)) {
$rules .= "if (\$request_uri ~ \"(" . implode('|', $exceptions) . ")\") {\n";
$rules .= " break;\n";
$rules .= "}\n";
}
$rules .= "if (\$request_uri ~* \\.(" . implode('|', $extensions) . ")\$) {\n";
$rules .= " return 404;\n";
$rules .= "}\n";
$rules .= W3TC_MARKER_END_BROWSERCACHE_NO404WP . "\n";
return $rules;
}
示例3: remove_scripts
/**
* Remove script tags from the source
*
* @param string $content
* @param array $files
* @return void
*/
function remove_scripts(&$content, $files)
{
$regexps = array();
$domain_url_regexp = w3_get_domain_url_regexp();
foreach ($files as $file) {
$this->replaced_scripts[] = $file;
if (w3_is_url($file) && !preg_match('~' . $domain_url_regexp . '~i', $file)) {
// external JS files
$regexps[] = w3_preg_quote($file);
} else {
// local JS files
$file = ltrim(preg_replace('~' . $domain_url_regexp . '~i', '', $file), '/\\');
$regexps[] = '(' . $domain_url_regexp . ')?/?' . w3_preg_quote($file);
}
}
foreach ($regexps as $regexp) {
$content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~Uis', '', $content);
}
}
示例4: _rewriteRelative
/**
* Rewrite a file relative URI as root relative
*
* <code>
* Minify_CSS_UriRewriter::rewriteRelative(
* '../img/hello.gif'
* , '/home/user/www/css' // path of CSS file
* , '/home/user/www' // doc root
* );
* // returns '/img/hello.gif'
*
* // example where static files are stored in a symlinked directory
* Minify_CSS_UriRewriter::rewriteRelative(
* 'hello.gif'
* , '/var/staticFiles/theme'
* , '/home/user/www'
* , array('/home/user/www/static' => '/var/staticFiles')
* );
* // returns '/static/theme/hello.gif'
* </code>
*
* @param string $uri file relative URI
*
* @param string $realCurrentDir realpath of the current file's directory.
*
* @param string $realDocRoot realpath of the site document root.
*
* @param array $symlinks (default = array()) If the file is stored in
* a symlink-ed directory, provide an array of link paths to
* real target paths, where the link paths "appear" to be within the document
* root. E.g.:
* <code>
* array('/home/foo/www/not/real/path' => '/real/target/path') // unix
* array('C:\\htdocs\\not\\real' => 'D:\\real\\target\\path') // Windows
* </code>
*
* @return string
*/
private static function _rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
{
if ('/' === $uri[0]) {
// root-relative
return $uri;
}
// prepend path with current dir separator (OS-independent)
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
self::$debugText .= "file-relative URI : {$uri}\n" . "path prepended : {$path}\n";
// "unresolve" a symlink back to doc root
foreach ($symlinks as $link => $target) {
if (0 === strpos($path, $target)) {
// replace $target with $link
$path = $link . substr($path, strlen($target));
self::$debugText .= "symlink unresolved : {$path}\n";
break;
}
}
// strip doc root
$path = substr($path, strlen($realDocRoot));
self::$debugText .= "docroot stripped : {$path}\n";
// fix to root-relative URI
$uri = strtr($path, '/\\', '//');
// remove /./ and /../ where possible
$uri = str_replace('/./', '/', $uri);
// inspired by patch from Oleg Cherniy
do {
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, 1, $changed);
} while ($changed);
self::$debugText .= "traversals removed : {$uri}\n\n";
$uri = preg_replace('~^' . w3_preg_quote(w3_get_base_path()) . '~', w3_get_site_path(), $uri);
return $uri;
}
示例5: w3_has_rules
/**
* Check if rules exist
*
* @param string $rules
* @param string $start
* @param string $end
* @return int
*/
function w3_has_rules($rules, $start, $end)
{
return preg_match('~' . w3_preg_quote($start) . "\n.*?" . w3_preg_quote($end) . "\n*~s", $rules);
}
示例6: w3_translate_file
/**
* Translates remote file to local file
*
* @param string $file
* @return string
*/
function w3_translate_file($file)
{
if (!w3_is_url($file)) {
$file = '/' . ltrim($file, '/');
$regexp = '~^' . w3_preg_quote(w3_get_site_path()) . '~';
$file = preg_replace($regexp, w3_get_base_path(), $file);
$file = ltrim($file, '/');
}
return $file;
}
示例7: get_regexp_by_mask
/**
* Returns regexp by mask
*
* @param string $mask
* @return string
*/
function get_regexp_by_mask($mask)
{
$mask = trim($mask);
$mask = w3_preg_quote($mask);
$mask = str_replace(array('\\*', '\\?', ';'), array('@ASTERISK@', '@QUESTION@', '|'), $mask);
$regexp = str_replace(array('@ASTERISK@', '@QUESTION@'), array('[^\\?\\*:\\|"<>]*', '[^\\?\\*:\\|"<>]'), $mask);
return $regexp;
}
示例8: clean_scripts
/**
* Cleans scripts
*
* @param string $content
* @return string
*/
function clean_scripts($content)
{
$regexps = array();
$groups = $this->_config->get_array('minify.js.groups');
$domain_url_regexp = w3_get_domain_url_regexp();
foreach ($groups as $group => $locations) {
foreach ((array) $locations as $location => $config) {
if (!empty($config['files'])) {
foreach ((array) $config['files'] as $file) {
if (w3_is_url($file) && !preg_match('~' . $domain_url_regexp . '~i', $file)) {
// external JS files
$regexps[] = w3_preg_quote($file);
} else {
// local JS files
$file = ltrim(preg_replace('~' . $domain_url_regexp . '~i', '', $file), '/\\');
$regexps[] = '(' . $domain_url_regexp . ')?/?' . w3_preg_quote($file);
}
}
}
}
}
foreach ($regexps as $regexp) {
$content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~is', '', $content);
}
return $content;
}
示例9: w3_get_domain_url_regexp
/**
* Returns domain url regexp
*
* @return string
*/
function w3_get_domain_url_regexp()
{
$domain_url = w3_get_domain_url();
$domain = preg_replace('~https?://~i', '', $domain_url);
$regexp = 'https?://' . w3_preg_quote($domain);
return $regexp;
}
示例10: get_regexp_by_mask
/**
* Returns regexp by mask
*
* @param string $mask
* @return string
*/
function get_regexp_by_mask($mask)
{
$regexp = str_replace(array('\\*', '\\?', '\\[', '\\]', ';'), array('[^\\s"\'>]*', '[^\\s"\'>]', '[', ']', '|'), w3_preg_quote($mask));
return $regexp;
}
示例11: make_uploads_regexes
/**
* @param $domain_url_regexp
* @param $baseurl
* @param $upload_info
* @param $regexps
* @return array
*/
private function make_uploads_regexes($domain_url_regexp, $baseurl, $upload_info, $regexps)
{
if (preg_match('~' . $domain_url_regexp . '~i', $baseurl)) {
$regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\')>]+)))~';
} else {
$parsed = @parse_url($baseurl);
$upload_url_domain_regexp = isset($parsed['host']) ? w3_get_url_regexp($parsed['scheme'] . '://' . $parsed['host']) : $domain_url_regexp;
$baseurlpath = isset($parsed['path']) ? rtrim($parsed['path'], '/') : '';
if ($baseurlpath) {
$regexps[] = '~(["\'])\\s*((' . $upload_url_domain_regexp . ')?(' . w3_preg_quote($baseurlpath) . '([^"\'>]+)))~';
} else {
$regexps[] = '~(["\'])\\s*((' . $upload_url_domain_regexp . ')(([^"\'>]+)))~';
}
}
return $regexps;
}