Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
function matches ($pattern, $content, $id)
{
if (preg_match_all ($pattern.$this->regex_options, $content, $matches, PREG_OFFSET_CAPTURE) > 0)
{
$results = array ();
// We found something
foreach ($matches[0] AS $found)
{
$result = new Result ();
$result->id = $id;
$result->offset = $found[1];
$result->length = strlen ($found[0]);
// Extract the context - surrounding 40 characters either side
// Index 0 is the match, index 1 is the position
$start = $found[1] - 40;
if ($start < 0)
$start = 0;
$end = $found[1] + 40;
if ($end > strlen ($content))
$end = strlen ($content);
$end -= $start;
$left = substr ($content, $start, $found[1] - $start);
$right = substr ($content, $found[1] + strlen ($found[0]), $end);
$result->left = $start;
$result->left_length = strlen ($found[0]) + ($found[1] - $start) + $end;
if ($start != 0)
$result->search = '… ';
$result->search .= htmlspecialchars ($left, HTML_ENTITIES, 'UTF-8');
$result->search .= '<a title="'.__ ('edit').'" onclick="return false;" ondblclick="regex_edit(\''.get_class ($this).'\','.$result->id.','.$result->offset.','.$result->length.'); return false" href="#">';
$result->search .= htmlspecialchars ($found[0], HTML_ENTITIES, 'UTF-8').'</a>';
$result->search .= htmlspecialchars ($right, HTML_ENTITIES, 'UTF-8');
$result->search_plain = htmlspecialchars ($left, HTML_ENTITIES, 'UTF-8');
$result->search_plain .= htmlspecialchars ($found[0], HTML_ENTITIES, 'UTF-8');
$result->search_plain .= htmlspecialchars ($right, HTML_ENTITIES, 'UTF-8');
if ($start + $end < strlen ($content))
$result->search .= ' …';
if (!is_null ($this->replace))
{
// Produce preview
$rep = preg_replace ($pattern.$this->regex_options, $this->replace, $found[0]);
$result->replace_string = $rep;
if ($start != 0)
$result->replace = '… ';
$result->replace .= htmlspecialchars ($left, HTML_ENTITIES, 'UTF-8');
$result->replace .= '<a title="'.__ ('edit').'" onclick="return false;" ondblclick="regex_edit_replace(\''.get_class ($this).'\','.$result->id.','.$result->offset.','.$result->length.'); return false" href="#">';
if ($rep != '')
$result->replace .= '<strong>'.htmlspecialchars ($rep, HTML_ENTITIES, 'UTF-8').'</strong></a>';
else
$result->replace .= '<strong>['.__ ('deleted','search-regex').']</strong></a>';
$result->replace .= htmlspecialchars ($right, HTML_ENTITIES, 'UTF-8');
$result->left_length_replace = strlen ($left) + strlen ($rep) + strlen ($right) + 1;
$result->replace_plain = htmlspecialchars ($left, HTML_ENTITIES, 'UTF-8');
$result->replace_plain .= htmlspecialchars ($rep, HTML_ENTITIES, 'UTF-8');
$result->replace_plain .= htmlspecialchars ($right, HTML_ENTITIES, 'UTF-8');
if ($start + $end < strlen ($content))
$result->replace .= ' …';
// And the real thing
$result->content = preg_replace ($pattern.$this->regex_options, $this->replace, $content);
}
$results[] = $result;
}
return $results;
}
return false;
}
$querystr = "
SELECT wposts.*
FROM {$wpdb->posts} wposts, {$wpdb->postmeta} wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND NOT ( wposts.post_content RLIKE "<img.*>")
ORDER BY wposts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
foreach ($pageposts as $post): {
setup_postdata($post);
?>
Здесь шаблон вывода поста, например:
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endforeach;
У меня не работает этот код. Wordpress 3.3.1Да, preg_match_all работает по другому нежели preg_match.
Короче, выбрать посты без картинок проще без плагинов:
Код:$querystr = " SELECT wposts.* FROM {$wpdb->posts} wposts, {$wpdb->postmeta} wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wposts.post_status = 'publish' AND wposts.post_type = 'post' AND NOT ( wposts.post_content RLIKE "<img.*>") ORDER BY wposts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT); foreach ($pageposts as $post): { setup_postdata($post); ?> Здесь шаблон вывода поста, например: <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach;
'/^(?>(?!(\<img.*src)).)*$/umi'
Не работает. Вы пробовали это применить в плагине?Вот тебе регулярное выражение, которое выберит все посты, кроме содержащих в них картинки:
Код:'/^(?>(?!(\<img.*src)).)*$/umi'
'(?i)(?s)^(?!(.*<img .*>)).*'
У меня работает,Не работает. Вы пробовали это применить в плагине?
<?php
$text = '
first line without links
sfsd flksjhdf l <img src="sddsf">
third line';
$pattern = '/^(?>(?!(\<img.*src)).)*$/umi';
$result = preg_match_all($pattern, $text, $matches);
print_r($matches);
(
[0] => Array
(
[0] =>
[1] => first line without links
[2] => third line
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
)