我在mysql数据库中有文本,比如:
<p>text text test text</p>
<p>demo demo demo</p>
我想写php脚本,在一个变量中回显"text-text-test-text",在另一个变量
试试这个
$charsToRemove = array('<p>','</p>');
$modifyString = str_ireplace($charsToRemove ,'',$string);
您希望数据库中的值显示什么?
然后,
如果您使用的是mysql、
$res = mysql_query("SELECT colName FROM tableName");
if(mysql_num_rows($res) > 0){
$ret = mysql_fetch_assoc($res);
echo $ret['colName'];
}
<?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";
?>
你只有两个<标签?如果没有,则需要循环$match[1]数组来检索所有。