本文整理汇总了PHP中wp_replace_in_html_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_replace_in_html_tags函数的具体用法?PHP wp_replace_in_html_tags怎么用?PHP wp_replace_in_html_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_replace_in_html_tags函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: autoembed
/**
* Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
*
* @uses WP_Embed::autoembed_callback()
*
* @param string $content The content to be searched.
* @return string Potentially modified $content.
*/
public function autoembed($content)
{
// Replace line breaks from all HTML elements with placeholders.
$content = wp_replace_in_html_tags($content, array("\n" => '<!-- wp-line-break -->'));
// Find URLs that are on their own line.
$content = preg_replace_callback('|^(\\s*)(https?://[^\\s"]+)(\\s*)$|im', array($this, 'autoembed_callback'), $content);
// Put the line breaks back.
return str_replace('<!-- wp-line-break -->', "\n", $content);
}
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:17,代码来源:class-wp-embed.php
示例2: wpautop
/**
* Replaces double line-breaks with paragraph elements.
*
* A group of regex replaces used to identify text formatted with newlines and
* replace double line-breaks with HTML paragraph tags. The remaining line-breaks
* after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
*
* @since 0.71
*
* @param string $pee The text which has to be formatted.
* @param bool $br Optional. If set, this will convert all remaining line-breaks
* after paragraphing. Default true.
* @return string Text which has been converted into correct paragraph tags.
*/
function wpautop($pee, $br = true)
{
$pre_tags = array();
if (trim($pee) === '') {
return '';
}
// Just to make things a little easier, pad the end.
$pee = $pee . "\n";
/*
* Pre tags shouldn't be touched by autop.
* Replace pre tags with placeholders and bring them back after autop.
*/
if (strpos($pee, '<pre') !== false) {
$pee_parts = explode('</pre>', $pee);
$last_pee = array_pop($pee_parts);
$pee = '';
$i = 0;
foreach ($pee_parts as $pee_part) {
$start = strpos($pee_part, '<pre');
// Malformed html?
if ($start === false) {
$pee .= $pee_part;
continue;
}
$name = "<pre wp-pre-tag-{$i}></pre>";
$pre_tags[$name] = substr($pee_part, $start) . '</pre>';
$pee .= substr($pee_part, 0, $start) . $name;
$i++;
}
$pee .= $last_pee;
}
// Change multiple <br>s into two line breaks, which will turn into paragraphs.
$pee = preg_replace('|<br\\s*/?>\\s*<br\\s*/?>|', "\n\n", $pee);
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
// Add a single line break above block-level opening tags.
$pee = preg_replace('!(<' . $allblocks . '[\\s/>])!', "\n\$1", $pee);
// Add a double line break below block-level closing tags.
$pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
// Standardize newline characters to "\n".
$pee = str_replace(array("\r\n", "\r"), "\n", $pee);
// Find newlines in all elements and add placeholders.
$pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
// Collapse line breaks before and after <option> elements so they don't get autop'd.
if (strpos($pee, '<option') !== false) {
$pee = preg_replace('|\\s*<option|', '<option', $pee);
$pee = preg_replace('|</option>\\s*|', '</option>', $pee);
}
/*
* Collapse line breaks inside <object> elements, before <param> and <embed> elements
* so they don't get autop'd.
*/
if (strpos($pee, '</object>') !== false) {
$pee = preg_replace('|(<object[^>]*>)\\s*|', '$1', $pee);
$pee = preg_replace('|\\s*</object>|', '</object>', $pee);
$pee = preg_replace('%\\s*(</?(?:param|embed)[^>]*>)\\s*%', '$1', $pee);
}
/*
* Collapse line breaks inside <audio> and <video> elements,
* before and after <source> and <track> elements.
*/
if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
$pee = preg_replace('%([<\\[](?:audio|video)[^>\\]]*[>\\]])\\s*%', '$1', $pee);
$pee = preg_replace('%\\s*([<\\[]/(?:audio|video)[>\\]])%', '$1', $pee);
$pee = preg_replace('%\\s*(<(?:source|track)[^>]*>)\\s*%', '$1', $pee);
}
// Remove more than two contiguous line breaks.
$pee = preg_replace("/\n\n+/", "\n\n", $pee);
// Split up the contents into an array of strings, separated by double line breaks.
$pees = preg_split('/\\n\\s*\\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
// Reset $pee prior to rebuilding.
$pee = '';
// Rebuild the content as a string, wrapping every bit with a <p>.
foreach ($pees as $tinkle) {
$pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
}
// Under certain strange conditions it could create a P of entirely whitespace.
$pee = preg_replace('|<p>\\s*</p>|', '', $pee);
// Add a closing <p> inside <div>, <address>, or <form> tag if missing.
$pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
// If an opening or closing block element tag is wrapped in a <p>, unwrap it.
$pee = preg_replace('!<p>\\s*(</?' . $allblocks . '[^>]*>)\\s*</p>!', "\$1", $pee);
// In some cases <li> may get wrapped in <p>, fix them.
$pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
// If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
//.........这里部分代码省略.........
开发者ID:zhoujiangyou,项目名称:WordPress,代码行数:101,代码来源:formatting.php
示例3: wpautop
/**
* Replaces double line-breaks with paragraph elements.
*
* A group of regex replaces used to identify text formatted with newlines and
* replace double line-breaks with HTML paragraph tags. The remaining
* line-breaks after conversion become <<br />> tags, unless $br is set to '0'
* or 'false'.
*
* @since 0.71
*
* @param string $pee The text which has to be formatted.
* @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
* @return string Text which has been converted into correct paragraph tags.
*/
function wpautop($pee, $br = true) {
$pre_tags = array();
if ( trim($pee) === '' )
return '';
$pee = $pee . "\n"; // just to make things a little easier, pad the end
if ( strpos($pee, '<pre') !== false ) {
$pee_parts = explode( '</pre>', $pee );
$last_pee = array_pop($pee_parts);
$pee = '';
$i = 0;
foreach ( $pee_parts as $pee_part ) {
$start = strpos($pee_part, '<pre');
// Malformed html?
if ( $start === false ) {
$pee .= $pee_part;
continue;
}
$name = "<pre wp-pre-tag-$i></pre>";
$pre_tags[$name] = substr( $pee_part, $start ) . '</pre>';
$pee .= substr( $pee_part, 0, $start ) . $name;
$i++;
}
$pee .= $last_pee;
}
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
// Space things out a little
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
// Strip newlines from all elements.
$pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );
if ( strpos($pee, '<object') !== false ) {
$pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
$pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
}
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
// make paragraphs, including one at the end
$pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
$pee = '';
foreach ( $pees as $tinkle )
$pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
$pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
if ( $br ) {
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
}
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
if ( !empty($pre_tags) )
$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
return $pee;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:89,代码来源:formatting.php
示例4: autoembed
/**
* Passes any unlinked URLs that are on their own line to WP_Embed::shortcode() for potential embedding.
*
* @see WP_Embed::autoembed_callback()
*
* @param string $content The content to be searched.
* @return string Potentially modified $content.
*/
public function autoembed($content)
{
// Replace line breaks from all HTML elements with placeholders.
$content = wp_replace_in_html_tags($content, array("\n" => '<!-- wp-line-break -->'));
if (preg_match('#(^|\\s|>)https?://#i', $content)) {
// Find URLs on their own line.
$content = preg_replace_callback('|^(\\s*)(https?://[^\\s<>"]+)(\\s*)$|im', array($this, 'autoembed_callback'), $content);
// Find URLs in their own paragraph.
$content = preg_replace_callback('|(<p(?: [^>]*)?>\\s*)(https?://[^\\s<>"]+)(\\s*<\\/p>)|i', array($this, 'autoembed_callback'), $content);
}
// Put the line breaks back.
return str_replace('<!-- wp-line-break -->', "\n", $content);
}
开发者ID:Garth619,项目名称:Femi9,代码行数:21,代码来源:class-wp-embed.php
示例5: convert_urls_omnyapp_to_shortcode_omny
public function convert_urls_omnyapp_to_shortcode_omny($post_id, $post, $update)
{
$content = wp_replace_in_html_tags($post->post_content, array("\n" => '<!-- wp-line-break -->'));
// Find the Omny URLs within the post_content
$omny_urls = array();
$has_omny_urls = preg_match_all(self::$embed_handlers['omnyapp']['regex'], $content, $omny_urls);
if (count($omny_urls) > 0 && $this->get_option('hooksavepost') == 'shortcode_omny') {
// Replace all the omnyapp.com URLs with [omny] shortcode text
$content = preg_replace_callback('|^(\\s*)(https?://[^\\s"]+)(\\s*)$|im', array($this, 'callback_omnyapp_to_shortcode_omny'), $content);
// Restore the linebreaks
$content = str_replace('<!-- wp-line-break -->', "\n", $content);
// unhook this function so it doesn't loop infinitely
remove_action('save_post', array($this, 'convert_urls_omnyapp_to_shortcode_omny'), 13, 3);
// update the post, which calls save_post again
wp_update_post(array('ID' => $post_id, 'post_content' => $content));
// re-hook this function
add_action('save_post', array($this, 'convert_urls_omnyapp_to_shortcode_omny'), 13, 3);
}
}
开发者ID:lvl99,项目名称:lvl99-omny-embed,代码行数:19,代码来源:lvl99-omny-embed.php
示例6: autoembed
/**
* Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
*
* @uses WP_Embed::autoembed_callback()
*
* @param string $content The content to be searched.
* @return string Potentially modified $content.
*/
public function autoembed($content)
{
// Strip newlines from all elements.
$content = wp_replace_in_html_tags($content, array("\n" => " "));
// Find URLs that are on their own line.
return preg_replace_callback('|^\\s*(https?://[^\\s"]+)\\s*$|im', array($this, 'autoembed_callback'), $content);
}
开发者ID:virendrayadav,项目名称:omfabric,代码行数:15,代码来源:class-wp-embed.php
示例7: test_wp_replace_in_html_tags
/**
* Check for expected behavior of new function wp_replace_in_html_tags().
*
* @dataProvider data_wp_replace_in_html_tags
*/
function test_wp_replace_in_html_tags($input, $output)
{
return $this->assertEquals($output, wp_replace_in_html_tags($input, array("\n" => " ")));
}
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:9,代码来源:WpReplaceInHtmlTags.php
注:本文中的wp_replace_in_html_tags函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论