0
<?php
$xml = simplexml_load_file("xmldocumentation.xml") 
   or die("Error: Cannot create object");


 foreach($xml->children() as $pages){
   foreach($pages->children() as $page => $data){
   echo $data->id;
   echo '<br>';
   echo $data->timestamp;
   //echo $data->revision;
   echo "<br />";
   echo str_replace("/===[^=]+===/","bold heading here", $data->text);
   echo '<p class="text">'.$data->text.'</p>';

  }
}

?>  

使用 php 我如何将由 php 的 str_replace 函数替换的文本加粗,并用粗体标题显示修改后的内容,即。' === 标题 === '?

谢谢

4

2 回答 2

1

改变

    echo str_replace("/===[^=]+===/","bold heading here", $data->text);

    $data->text = preg_replace("/===([^=])+===/","<strong>$1</strong>", $data->text);

您需要preg_replace正则表达式,并且需要捕获要加粗的文本(通过()),然后将该文本包含在 HTML 元素中,该元素将为您提供所需的格式。

于 2013-02-12T21:30:50.627 回答
0

一个<b> </b>可以做的伎俩!

$strlst = 'lorem ipsum';

$strlst = explode( ' ' , $strlst );
function wrapTag($inVal){
   return '<b>'.$inVal.'</b>';
}
$replace = array_map( 'wrapTag' , $strlst );

$Content = str_replace( $strlst , $replace , $Content );

echo $Content;
于 2013-02-12T21:33:17.100 回答