2

PHP を使用してページ内の HTML を検索し、その HTML を他の HTML に置き換える方法はありますか? この関数を個別の functions.php ファイルに入れ、ページ読み込み時に各ページを調べて、置換が必要な HTML を探します (これが他の方法ほど効率的でない場合を除きます)。ありがとう!

4

1 に答える 1

3
//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);
?>

関数の使用に関するヒントについては、このhttp://codex.wordpress.org/Function_Reference/the_contentを読むことも検討してください。the_content()

于 2013-02-14T21:28:49.117 に答える