使用PHP将HTML替换为HTML [英] Use PHP to Replace HTML with HTML

查看:752
本文介绍了使用PHP将HTML替换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用PHP在页面中找到一些HTML,并用其他HTML代替HTML?我想这个函数是在一个单独的functions.php文件中,并查看页面加载的每个页面的HTML需要替换(除非这是不如其他方法的效率)。感谢!

解决方案

  //函数添加到您的函数定义中。 
函数print_processed_html($ string)
{
$ search = Array( - ,*,\ *,^,\ ^);
$ replace = Array(< \ hr>,< b>,< \ b>,⊃>,< \ sup> ;

$ processed_string = str_replace($ search,$ replace,$ string);

echo $ processed_string;
}


//输出字符串到页面。
<?php
$ the_content = get_the_content();
print_processed_html($ the_content);
?>

也可以通过阅读 the_content()函数的一些技巧 / p>

Is there a way to use PHP to find some HTML within a page, and replace that HTML with other HTML? I'd like for this function to be in a separate functions.php file, and look at each page on page-load for the HTML that needs replacing (unless this isn't as efficient as some other method). Thanks!

//function to add to your function definitions. 
function print_processed_html($string)
{ 
    $search  = Array("--", "*", "\*", "^", "\^");
    $replace = Array("<\hr>", "<b>", "<\b>", "<sup>", "<\sup>");

    $processed_string = str_replace($search, $replace , $string);

    echo $processed_string;
 }


// outputing the string to the page.
<?php 
      $the_content = get_the_content();
      print_processed_html($the_content);
?>

also consider reading through this http://codex.wordpress.org/Function_Reference/the_content for some tips on using the the_content() function

这篇关于使用PHP将HTML替换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆