0

我在 mysql 数据库中有如下文本:

<p>text text test text</p>
<p>demo demo demo</p>

我想编写 php 脚本以在变量中回显“文本文本测试文本”并在另一个变量中回显“演示演示演示”

4

3 回答 3

1

尝试这个

$charsToRemove =   array('<p>','</p>');
$modifyString  =   str_ireplace($charsToRemove ,'',$string);
于 2012-09-15T04:10:58.877 回答
0

您希望显示数据库中的值是什么?

然后,

如果你使用 mysql,

  $res = mysql_query("SELECT colName FROM tableName");
  if(mysql_num_rows($res) > 0){
     $ret = mysql_fetch_assoc($res);
     echo $ret['colName'];
  }
于 2012-09-15T04:04:11.860 回答
0
<?php
$html="<p>text text test text</p><p>demo demo demo</p>";
preg_match_all("'<p>(.*?)</p>'si", $html, $match);
if ($match) {
    $var1 = $match[1][0];
    $var2 = $match[1][1];
}
echo $var1."\n";
echo $var2."\n";
?>

你只有两个 < p > 标签吗?如果不是,您需要循环 $match[1] 数组以检索所有内容。

于 2012-09-15T04:12:12.967 回答